Skip to content

Commit 5208599

Browse files
committed
refactor: remove tesetify usage
The github.com/stretchr/testify/assert module currently pulls in a version of the gopkg.in/yaml.v3 module that flags up a vulnerability. This is used for testing only, and only in an isolated spot. Removing use of this package in tests cuts the dependencies of this module in half, which makes it easier to maintain as well as easier to adopt.
1 parent 622813e commit 5208599

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

client/push_test.go

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2018-2020, Sylabs Inc. All rights reserved.
1+
// Copyright (c) 2018-2022, Sylabs Inc. All rights reserved.
22
// This software is licensed under a 3-clause BSD license. Please consult the
33
// LICENSE.md file distributed with the sources of this project regarding your
44
// rights to use or distribute this software.
@@ -14,7 +14,6 @@ import (
1414
"os"
1515
"testing"
1616

17-
"github.com/stretchr/testify/assert"
1817
jsonresp "github.com/sylabs/json-resp"
1918
)
2019

@@ -139,7 +138,9 @@ func (m *v2ImageUploadMockService) MockImageFileEndpoint(w http.ResponseWriter,
139138
// request. There is no actual validation of the sha256 checksum of the
140139
// payload in the PUT request.
141140
const expectedSha256 = "d7d356079af905c04e5ae10711ecf3f5b34385e9b143c5d9ddbf740665ce2fb7"
142-
assert.Equal(m.t, expectedSha256, uploadImageRequest.SHA256Checksum)
141+
if got, want := uploadImageRequest.SHA256Checksum, expectedSha256; got != want {
142+
m.t.Errorf("got checksum %v, want %v", got, want)
143+
}
143144

144145
response := UploadImage{
145146
UploadURL: m.baseURI + "/fake/s3/endpoint?key=value",
@@ -214,25 +215,48 @@ func Test_legacyPostFileV2(t *testing.T) {
214215

215216
// calculate sha256 checksum
216217
sha256checksum, _, err := sha256sum(f)
217-
assert.NoError(t, err, "error calculating sha256 checksum")
218+
if err != nil {
219+
t.Fatalf("error calculating sha256 checksum: %v", err)
220+
}
221+
218222
_, err = f.Seek(0, 0)
219-
assert.NoError(t, err, "unexpected error seeking in sample data file")
223+
if err != nil {
224+
t.Fatalf("unexpected error seeking in sample data file: %v", err)
225+
}
220226

221227
callback := &defaultUploadCallback{r: f}
222228

223229
// include sha256 checksum in metadata
224230
resp, err := c.legacyPostFileV2(context.Background(), fileSize, tt.imageRef, callback, map[string]string{
225231
"sha256sum": sha256checksum,
226232
})
227-
assert.NoErrorf(t, err, "unexpected error")
233+
if err != nil {
234+
t.Fatalf("unexpected error: %v", err)
235+
}
236+
237+
if got, want := resp.Quota.QuotaUsageBytes, testQuotaUsageBytes; got != want {
238+
t.Errorf("got quota usage %v, want %v", got, want)
239+
}
228240

229-
assert.Equal(t, testQuotaUsageBytes, resp.Quota.QuotaUsageBytes)
230-
assert.Equal(t, testQuotaTotalBytes, resp.Quota.QuotaTotalBytes)
231-
assert.Equal(t, testContainerURL, resp.ContainerURL)
241+
if got, want := resp.Quota.QuotaTotalBytes, testQuotaTotalBytes; got != want {
242+
t.Errorf("got quota total %v, want %v", got, want)
243+
}
232244

233-
assert.True(t, m.initCalled, "init image upload request was not made")
234-
assert.True(t, m.putCalled, "file PUT request was not made")
235-
assert.True(t, m.completeCalled, "image upload complete request was not made")
245+
if got, want := resp.ContainerURL, testContainerURL; got != want {
246+
t.Errorf("got container URL %v, want %v", got, want)
247+
}
248+
249+
if !m.initCalled {
250+
t.Errorf("init image upload request was not made")
251+
}
252+
253+
if !m.putCalled {
254+
t.Errorf("file PUT request was not made")
255+
}
256+
257+
if !m.completeCalled {
258+
t.Errorf("image upload complete request was not made")
259+
}
236260
})
237261
}
238262
}

go.mod

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ go 1.17
55
require (
66
github.com/blang/semver/v4 v4.0.0
77
github.com/go-log/log v0.2.0
8-
github.com/stretchr/testify v1.7.1
98
github.com/sylabs/json-resp v0.8.1
109
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29
1110
)
12-
13-
require (
14-
github.com/davecgh/go-spew v1.1.0 // indirect
15-
github.com/pmezard/go-difflib v1.0.0 // indirect
16-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
17-
)

go.sum

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
22
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
3-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
4-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
53
github.com/go-log/log v0.2.0 h1:z8i91GBudxD5L3RmF0KVpetCbcGWAV7q1Tw1eRwQM9Q=
64
github.com/go-log/log v0.2.0/go.mod h1:xzCnwajcues/6w7lne3yK2QU7DBPW7kqbgPGG5AF65U=
7-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
8-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
9-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
10-
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
11-
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
125
github.com/sylabs/json-resp v0.8.1 h1:3KF04WzGizDVlROeI4DK4B0f9p7XKb0BRTFzI7wPTG8=
136
github.com/sylabs/json-resp v0.8.1/go.mod h1:bUGV9cqShOyxz7RxBq03Yt9raKGfELKrfN6Yac3lfiw=
147
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 h1:w8s32wxx3sY+OjLlv9qltkLU5yvJzxjjgiHWLjdIcw4=
158
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
16-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
17-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
18-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
19-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)