Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit f99d4c7

Browse files
committed
Change tests to use standard library, more idiomatic style.
The motivation for using idiomatic style and standard library for tests is that it's more universal, and more familiar to a larger set of people. It makes it easier to read, modify tests for experienced Go programmers. It does not require thorough knowledge and familiarity with custom APIs. Resolves #41. This commit is largely based on previous work by @uovobw in sourcegraph#3, modified by me to improve error messages, style, and address preliminary review comments.
1 parent 4b02602 commit f99d4c7

File tree

5 files changed

+666
-362
lines changed

5 files changed

+666
-362
lines changed

‎diskcache/diskcache_test.go‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,38 @@ import (
55
"io/ioutil"
66
"os"
77
"testing"
8-
9-
. "gopkg.in/check.v1"
108
)
119

12-
func Test(t *testing.T) { TestingT(t) }
13-
14-
type S struct{}
15-
16-
var _ = Suite(&S{})
17-
18-
func (s *S) Test(c *C) {
10+
func TestDiskCache(t *testing.T) {
1911
tempDir, err := ioutil.TempDir("", "httpcache")
2012
if err != nil {
21-
c.Fatalf("TempDir,: %v", err)
13+
t.Fatalf("TempDir: %v", err)
2214
}
2315
defer os.RemoveAll(tempDir)
2416

2517
cache := New(tempDir)
2618

2719
key := "testKey"
2820
_, ok := cache.Get(key)
29-
30-
c.Assert(ok, Equals, false)
21+
if ok {
22+
t.Fatal("retrieved key before adding it")
23+
}
3124

3225
val := []byte("some bytes")
3326
cache.Set(key, val)
3427

3528
retVal, ok := cache.Get(key)
36-
c.Assert(ok, Equals, true)
37-
c.Assert(bytes.Equal(retVal, val), Equals, true)
29+
if !ok {
30+
t.Fatal("could not retrieve an element we just added")
31+
}
32+
if !bytes.Equal(retVal, val) {
33+
t.Fatal("retrieved a different value than what we put in")
34+
}
3835

3936
cache.Delete(key)
4037

4138
_, ok = cache.Get(key)
42-
c.Assert(ok, Equals, false)
39+
if ok {
40+
t.Fatal("deleted key still present")
41+
}
4342
}

0 commit comments

Comments
 (0)