Skip to content

Commit

Permalink
test: unexported key
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuigo committed Nov 30, 2024
1 parent 4a3383f commit 67e0082
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
28 changes: 27 additions & 1 deletion examples/decorator-key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,38 @@ func TestCacheFuncKeyStruct(t *testing.T) {
}
getUserScoreFromDbWithCache(UserInfo{id: 2})
getUserScoreFromDbWithCache(UserInfo{id: 3})
}, 10)
}, 5)

if executeCount != 3 {
t.Errorf("executeCount should be 3, but get %d", executeCount)
}
}
func TestCacheFuncKeyStructUnexportedKey(t *testing.T) {
type info struct{
name string // unexported field
}

type UserInfo struct {
info struct{
name string // unexported field
}
}
// Original function
getUserName := func(user UserInfo, flag *string) string {
return user.info.name
}

// Cacheable Function
getUserName2 := gofnext.CacheFn2(getUserName, )

// Execute the function
flag := "flag"
name := getUserName2(UserInfo{info{name: "Alex"}}, &flag)
if name != "Alex" {
t.Errorf("name should be 'Alex', but get %s", name)
}

}

func TestCacheFuncKeyMap(t *testing.T) {
// Original function
Expand Down
1 change: 1 addition & 0 deletions examples/decorator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func TestCacheFuncWithMoreParams(t *testing.T) {

// Original function
fn := func(name string, age, gender, height int) int {
_ = age+ gender+ height
executeCount++
// select score from db where name=name and age=age and gender=gender
switch name {
Expand Down

0 comments on commit 67e0082

Please sign in to comment.