From d0159e9f66a55ffa02fd4f0adbf36d49c04379a6 Mon Sep 17 00:00:00 2001 From: soulteary Date: Mon, 10 Oct 2022 14:39:30 +0800 Subject: [PATCH] chore: reduce test deps --- go.mod | 11 +---------- go.sum | 15 --------------- pkg/httpcache/cache_test.go | 16 +++++++++++---- pkg/httpcache/cachecontrol_test.go | 11 +++++++---- pkg/httpcache/spec_test.go | 31 +++++++++++++++++++----------- 5 files changed, 40 insertions(+), 44 deletions(-) diff --git a/go.mod b/go.mod index c638d94..7f76f77 100644 --- a/go.mod +++ b/go.mod @@ -2,15 +2,6 @@ module github.com/soulteary/apt-proxy go 1.19 -require ( - github.com/stretchr/testify v1.8.0 - golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875 -) - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) +require golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875 replace github.com/soulteary/apt-proxy => ./ diff --git a/go.sum b/go.sum index f494eef..e04231f 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,2 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875 h1:AzgQNqF+FKwyQ5LbVrVqOcuuFB67N47F9+htZYH0wFM= golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/httpcache/cache_test.go b/pkg/httpcache/cache_test.go index 0fdac8e..d4442e2 100644 --- a/pkg/httpcache/cache_test.go +++ b/pkg/httpcache/cache_test.go @@ -2,11 +2,11 @@ package httpcache_test import ( "net/http" + "reflect" "strings" "testing" "github.com/soulteary/apt-proxy/pkg/httpcache" - "github.com/stretchr/testify/require" ) func TestSaveResource(t *testing.T) { @@ -26,9 +26,17 @@ func TestSaveResource(t *testing.T) { t.Fatal(err) } - require.NotNil(t, resOut) - require.Equal(t, res.Header(), resOut.Header()) - require.Equal(t, body, readAllString(resOut)) + if resOut == nil { + t.Fatalf("resOut should not be null") + } + + if !reflect.DeepEqual(res.Header(), resOut.Header()) { + t.Fatalf("header should be equal") + } + + if body != readAllString(resOut) { + t.Fatalf("body should be equal") + } } func TestSaveResourceWithIncorrectContentLength(t *testing.T) { diff --git a/pkg/httpcache/cachecontrol_test.go b/pkg/httpcache/cachecontrol_test.go index e220fb1..b726ccb 100644 --- a/pkg/httpcache/cachecontrol_test.go +++ b/pkg/httpcache/cachecontrol_test.go @@ -1,10 +1,10 @@ package httpcache_test import ( + "reflect" "testing" . "github.com/soulteary/apt-proxy/pkg/httpcache" - "github.com/stretchr/testify/require" ) func TestParsingCacheControl(t *testing.T) { @@ -40,9 +40,12 @@ func TestParsingCacheControl(t *testing.T) { if err != nil { t.Fatal(err) } - - require.Equal(t, cc, expect.ccStruct) - require.NotEmpty(t, cc.String()) + if !reflect.DeepEqual(cc, expect.ccStruct) { + t.Fatalf("cc should be equal") + } + if cc.String() == "" { + t.Fatalf("cc string should not be empty") + } } } diff --git a/pkg/httpcache/spec_test.go b/pkg/httpcache/spec_test.go index 7b23070..473b1ec 100644 --- a/pkg/httpcache/spec_test.go +++ b/pkg/httpcache/spec_test.go @@ -1,18 +1,16 @@ package httpcache_test import ( - "fmt" "io/ioutil" "log" "net/http" + "reflect" "strings" "testing" "time" "github.com/soulteary/apt-proxy/pkg/httpcache" "github.com/soulteary/apt-proxy/pkg/httplog" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func testSetup() (*client, *upstreamServer) { @@ -88,12 +86,14 @@ func TestSpecResponseCacheControl(t *testing.T) { t.Fatalf("HTTP status code: %d not equal Status OK", r.statusCode) } - require.Equal(t, c.requests, upstream.requests, - fmt.Sprintf("case #%d failed, %+v", idx+1, c)) + if c.requests != upstream.requests { + t.Fatalf("case #%d failed, %+v", idx+1, c) + } if c.cacheStatus != "" { - require.Equal(t, c.cacheStatus, r.cacheStatus, - fmt.Sprintf("case #%d failed, %+v", idx+1, c)) + if c.cacheStatus != r.cacheStatus { + t.Fatalf("case #%d failed, %+v", idx+1, c) + } } } } @@ -340,8 +340,12 @@ func TestSpecHeuristicCaching(t *testing.T) { if strings.Compare("HIT", r2.cacheStatus) != 0 { t.Fatalf("Cache status: %s not equal", r2.cacheStatus) } - assert.Equal(t, []string{"113 - \"Heuristic Expiration\""}, r2.Header()["Warning"]) - assert.Equal(t, 1, upstream.requests, "The second request shouldn't validate") + if !reflect.DeepEqual([]string{"113 - \"Heuristic Expiration\""}, r2.Header()["Warning"]) { + t.Fatal("headers are not equal") + } + if upstream.requests != 1 { + t.Fatal("The second request shouldn't validate") + } } func TestSpecCacheControlTrumpsExpires(t *testing.T) { @@ -532,7 +536,10 @@ func TestSpecHeadersPropagated(t *testing.T) { if strings.Compare("HIT", r2.cacheStatus) != 0 { t.Fatalf("Cache status: %s not equal", r2.cacheStatus) } - assert.Equal(t, []string{"1", "3", "2"}, r2.Header()["X-Llamas"]) + + if !reflect.DeepEqual([]string{"1", "3", "2"}, r2.Header()["X-Llamas"]) { + t.Fatal("headers are not equal") + } } func TestSpecAgeHeaderFromUpstream(t *testing.T) { @@ -596,7 +603,9 @@ func TestSpecWarningForOldContent(t *testing.T) { if strings.Compare("HIT", r2.cacheStatus) != 0 { t.Fatalf("Cache status: %s not equal", r2.cacheStatus) } - assert.Equal(t, []string{"113 - \"Heuristic Expiration\""}, r2.Header()["Warning"]) + if !reflect.DeepEqual([]string{"113 - \"Heuristic Expiration\""}, r2.Header()["Warning"]) { + t.Fatal("headers are not equal") + } } func TestSpecHeadCanBeServedFromCacheOnlyWithExplicitFreshness(t *testing.T) {