This repository has been archived by the owner on Apr 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add a helper for testing cache implementations (#91)
This DRYs things up a bit (and gives me a single place to edit the tests when I get around to streaming caches).
- Loading branch information
Showing
7 changed files
with
60 additions
and
128 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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package test | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/gregjones/httpcache" | ||
) | ||
|
||
// Cache excercises a httpcache.Cache implementation. | ||
func Cache(t *testing.T, cache httpcache.Cache) { | ||
key := "testKey" | ||
_, ok := cache.Get(key) | ||
if ok { | ||
t.Fatal("retrieved key before adding it") | ||
} | ||
|
||
val := []byte("some bytes") | ||
cache.Set(key, val) | ||
|
||
retVal, ok := cache.Get(key) | ||
if !ok { | ||
t.Fatal("could not retrieve an element we just added") | ||
} | ||
if !bytes.Equal(retVal, val) { | ||
t.Fatal("retrieved a different value than what we put in") | ||
} | ||
|
||
cache.Delete(key) | ||
|
||
_, ok = cache.Get(key) | ||
if ok { | ||
t.Fatal("deleted key still present") | ||
} | ||
} |
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,12 @@ | ||
package test_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gregjones/httpcache" | ||
"github.com/gregjones/httpcache/test" | ||
) | ||
|
||
func TestMemoryCache(t *testing.T) { | ||
test.Cache(t, httpcache.NewMemoryCache()) | ||
} |