-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package examples | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
"time" | ||
|
||
"github.com/ahuigo/gofnext" | ||
) | ||
|
||
func TestRedisCacheClientPanic(t *testing.T) { | ||
defer func() { | ||
r := recover() //r.(string) | ||
if r==nil{ | ||
t.Error("should panic") | ||
} | ||
}() | ||
gofnext.NewCacheRedis("") | ||
|
||
} | ||
|
||
func TestRedisCacheFuncErr(t *testing.T) { | ||
// Original function | ||
executeCount := 0 | ||
getUserScore := func(more int) (int, error) { | ||
executeCount++ | ||
return 98 + more, errors.New("db error") | ||
} | ||
|
||
// Cacheable Function | ||
getUserScoreFromDbWithCache := gofnext.CacheFn1Err(getUserScore, &gofnext.Config{ | ||
TTL: 500*time.Second, | ||
CacheMap: gofnext.NewCacheRedis("redis-cache-key").ClearAll(), | ||
}) | ||
|
||
// Parallel invocation of multiple functions. | ||
for i := 0; i < 10; i++ { | ||
score, err := getUserScoreFromDbWithCache(1) | ||
if err == nil { | ||
t.Errorf("should be error, but get nil") | ||
} | ||
if score != 99 { | ||
t.Errorf("score should be 99, but get %d", score) | ||
} | ||
score, _ = getUserScoreFromDbWithCache(2) | ||
if score != 100 { | ||
t.Fatalf("score should be 100, but get %d", score) | ||
} | ||
getUserScoreFromDbWithCache(3) | ||
getUserScoreFromDbWithCache(3) | ||
} | ||
|
||
if executeCount != 3 { | ||
t.Errorf("executeCount should be 1, but get %d", executeCount) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v0.0.14 | ||
v0.0.15 |