Skip to content

Commit 7cf7ab6

Browse files
authored
Cleanup: remove old assert library, update test to use canonical comparisons (#67)
1 parent 825965f commit 7cf7ab6

File tree

3 files changed

+26
-37
lines changed

3 files changed

+26
-37
lines changed

go.mod

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@ module github.com/suyashkumar/ssl-proxy
22

33
go 1.24
44

5-
require (
6-
github.com/stretchr/testify v1.7.0
7-
golang.org/x/crypto v0.36.0
8-
)
5+
require golang.org/x/crypto v0.36.0
96

107
require (
11-
github.com/davecgh/go-spew v1.1.0 // indirect
12-
github.com/pmezard/go-difflib v1.0.0 // indirect
138
golang.org/x/net v0.37.0 // indirect
149
golang.org/x/text v0.23.0 // indirect
15-
gopkg.in/yaml.v3 v3.0.0 // indirect
1610
)

go.sum

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
1-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2-
github.com/davecgh/go-spew v1.1.0/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/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
6-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
7-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
8-
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
9-
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
101
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
112
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
12-
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
13-
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
143
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
154
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
16-
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
17-
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
185
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
196
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
20-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
21-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
22-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
23-
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
24-
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

reverseproxy/reverseproxy_test.go

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,36 @@ import (
66
"net/http/httputil"
77
"net/url"
88
"testing"
9-
10-
"github.com/stretchr/testify/assert"
119
)
1210

1311
// TestBuild_AddHeaders tests that Build's returned ReverseProxy Director adds the proper request headers
1412
func TestBuild_AddHeaders(t *testing.T) {
1513
u, err := url.Parse("http://127.0.0.1")
16-
assert.Nil(t, err, "error should be nil")
14+
if err != nil {
15+
t.Fatalf("got error %v, want nil", err)
16+
}
1717
proxy := Build(u)
18-
assert.NotNil(t, proxy, "Build should not return nil")
18+
if proxy == nil {
19+
t.Fatal("got nil, want non-nil proxy")
20+
}
1921

2022
req := httptest.NewRequest("GET", "/test", nil)
2123
proxy.Director(req)
2224

2325
// Check that headers were added to req
24-
assert.Equal(t, req.Header.Get(http.CanonicalHeaderKey("X-Forwarded-Proto")), "https",
25-
"X-Forwarded-Proto should be present")
26-
assert.Equal(t, req.Header.Get(http.CanonicalHeaderKey("X-Forwarded-Port")), "443",
27-
"X-Forwarded-Port should be present")
28-
26+
if got := req.Header.Get(http.CanonicalHeaderKey("X-Forwarded-Proto")); got != "https" {
27+
t.Errorf("X-Forwarded-Proto: got %q, want %q", got, "https")
28+
}
29+
if got := req.Header.Get(http.CanonicalHeaderKey("X-Forwarded-Port")); got != "443" {
30+
t.Errorf("X-Forwarded-Port: got %q, want %q", got, "443")
31+
}
2932
}
3033

3134
func TestNewDirector(t *testing.T) {
3235
u, err := url.Parse("http://127.0.0.1")
33-
assert.Nil(t, err, "error should be nil")
36+
if err != nil {
37+
t.Fatalf("got error %v, want nil", err)
38+
}
3439
director := newDirector(u, nil)
3540

3641
defaultProxy := httputil.NewSingleHostReverseProxy(u)
@@ -42,7 +47,15 @@ func TestNewDirector(t *testing.T) {
4247
defaultDirector(expectedReq)
4348
director(testReq)
4449

45-
assert.EqualValues(t, expectedReq, testReq,
46-
"default proxy and package directors should modify the request in the same way")
50+
// Compare relevant fields of the requests
51+
if got, want := testReq.URL.String(), expectedReq.URL.String(); got != want {
52+
t.Errorf("URL: got %q, want %q", got, want)
53+
}
54+
if got, want := testReq.Host, expectedReq.Host; got != want {
55+
t.Errorf("Host: got %q, want %q", got, want)
56+
}
57+
if got, want := testReq.RemoteAddr, expectedReq.RemoteAddr; got != want {
58+
t.Errorf("RemoteAddr: got %q, want %q", got, want)
59+
}
4760
// TODO: add more test cases
4861
}

0 commit comments

Comments
 (0)