Skip to content

Commit

Permalink
chore: reduce test deps
Browse files Browse the repository at this point in the history
  • Loading branch information
soulteary committed Oct 10, 2022
1 parent 76689ea commit d0159e9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 44 deletions.
11 changes: 1 addition & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ./
15 changes: 0 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
16 changes: 12 additions & 4 deletions pkg/httpcache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
11 changes: 7 additions & 4 deletions pkg/httpcache/cachecontrol_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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")
}
}
}

Expand Down
31 changes: 20 additions & 11 deletions pkg/httpcache/spec_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d0159e9

Please sign in to comment.