1
- // Copyright (c) 2018-2020 , Sylabs Inc. All rights reserved.
1
+ // Copyright (c) 2018-2022 , Sylabs Inc. All rights reserved.
2
2
// This software is licensed under a 3-clause BSD license. Please consult the
3
3
// LICENSE.md file distributed with the sources of this project regarding your
4
4
// rights to use or distribute this software.
@@ -14,7 +14,6 @@ import (
14
14
"os"
15
15
"testing"
16
16
17
- "github.com/stretchr/testify/assert"
18
17
jsonresp "github.com/sylabs/json-resp"
19
18
)
20
19
@@ -139,7 +138,9 @@ func (m *v2ImageUploadMockService) MockImageFileEndpoint(w http.ResponseWriter,
139
138
// request. There is no actual validation of the sha256 checksum of the
140
139
// payload in the PUT request.
141
140
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
+ }
143
144
144
145
response := UploadImage {
145
146
UploadURL : m .baseURI + "/fake/s3/endpoint?key=value" ,
@@ -214,25 +215,48 @@ func Test_legacyPostFileV2(t *testing.T) {
214
215
215
216
// calculate sha256 checksum
216
217
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
+
218
222
_ , 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
+ }
220
226
221
227
callback := & defaultUploadCallback {r : f }
222
228
223
229
// include sha256 checksum in metadata
224
230
resp , err := c .legacyPostFileV2 (context .Background (), fileSize , tt .imageRef , callback , map [string ]string {
225
231
"sha256sum" : sha256checksum ,
226
232
})
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
+ }
228
240
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
+ }
232
244
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
+ }
236
260
})
237
261
}
238
262
}
0 commit comments