Skip to content

Commit e816eec

Browse files
committed
don't use testify lib
1 parent 6877e17 commit e816eec

File tree

5 files changed

+13
-31
lines changed

5 files changed

+13
-31
lines changed

2-race-in-cache/check_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import (
1010
"strconv"
1111
"sync"
1212
"testing"
13-
14-
"github.com/stretchr/testify/assert"
1513
)
1614

1715
func TestMain(t *testing.T) {
18-
cache, db := run(assert.New(t))
16+
cache, db := run(t)
1917

2018
cacheLen := len(cache.cache)
2119
pagesLen := cache.pages.Len()
@@ -41,7 +39,9 @@ func TestLRU(t *testing.T) {
4139
wg.Add(1)
4240
go func(i int) {
4341
value := cache.Get("Test" + strconv.Itoa(i))
44-
assert.Equal(t, "Test" + strconv.Itoa(i), value)
42+
if value != "Test" + strconv.Itoa(i) {
43+
t.Errorf("Incorrect db response %v", value)
44+
}
4545
wg.Done()
4646
}(i)
4747
}

2-race-in-cache/main.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ package main
1010

1111
import (
1212
"container/list"
13-
14-
"github.com/stretchr/testify/assert"
13+
"testing"
1514
)
1615

1716
// CacheSize determines how big the cache can grow
@@ -79,13 +78,13 @@ func (l *Loader) Load(key string) string {
7978
return val
8079
}
8180

82-
func run(as *assert.Assertions) (*KeyStoreCache, *MockDB) {
81+
func run(t *testing.T) (*KeyStoreCache, *MockDB) {
8382
loader := Loader{
8483
DB: GetMockDB(),
8584
}
8685
cache := New(&loader)
8786

88-
RunMockServer(cache, as)
87+
RunMockServer(cache, t)
8988

9089
return cache, loader.DB
9190
}

2-race-in-cache/mockserver.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ package main
99
import (
1010
"strconv"
1111
"sync"
12-
13-
"github.com/stretchr/testify/assert"
12+
"testing"
1413
)
1514

1615
const (
@@ -20,7 +19,7 @@ const (
2019

2120
// RunMockServer simulates a running server, which accesses the
2221
// key-value database through our cache
23-
func RunMockServer(cache *KeyStoreCache, as *assert.Assertions) {
22+
func RunMockServer(cache *KeyStoreCache, t *testing.T) {
2423
var wg sync.WaitGroup
2524

2625
for c := 0; c < cycles; c++ {
@@ -31,8 +30,10 @@ func RunMockServer(cache *KeyStoreCache, as *assert.Assertions) {
3130
wg.Add(1)
3231
go func(i int) {
3332
value := cache.Get("Test" + strconv.Itoa(i))
34-
if as != nil {
35-
as.Equal("Test" + strconv.Itoa(i), value)
33+
if t != nil {
34+
if value != "Test" + strconv.Itoa(i) {
35+
t.Errorf("Incorrect db response %v", value)
36+
}
3637
}
3738
wg.Done()
3839
}(i)

go.mod

-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
module github.com/loong/go-concurrency-exercises
22

33
go 1.19
4-
5-
require github.com/stretchr/testify v1.8.4
6-
7-
require (
8-
github.com/davecgh/go-spew v1.1.1 // indirect
9-
github.com/pmezard/go-difflib v1.0.0 // indirect
10-
gopkg.in/yaml.v3 v3.0.1 // indirect
11-
)

go.sum

-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +0,0 @@
1-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5-
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
6-
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
7-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
8-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9-
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10-
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)