mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-09-17 11:34:45 -04:00
Ref/want err from err expected (#82)
consistent naming for test values using 'want' instead of 'expect/ed'
This commit is contained in:
parent
6265b307af
commit
51068abc27
91 changed files with 2319 additions and 2319 deletions
|
@ -43,21 +43,21 @@ func (s *stubAWSS3StorageClient) CreateBucket(ctx context.Context, params *s3.Cr
|
|||
|
||||
func TestAWSS3Get(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
client *stubAWSS3StorageClient
|
||||
unsetError bool
|
||||
errExpected bool
|
||||
client *stubAWSS3StorageClient
|
||||
unsetError bool
|
||||
wantErr bool
|
||||
}{
|
||||
"Get successful": {
|
||||
client: &stubAWSS3StorageClient{getObjectOutputData: []byte("test-data")},
|
||||
},
|
||||
"GetObject fails": {
|
||||
client: &stubAWSS3StorageClient{getObjectErr: errors.New("error")},
|
||||
errExpected: true,
|
||||
client: &stubAWSS3StorageClient{getObjectErr: errors.New("error")},
|
||||
wantErr: true,
|
||||
},
|
||||
"GetObject fails with NoSuchKey": {
|
||||
client: &stubAWSS3StorageClient{getObjectErr: &types.NoSuchKey{}},
|
||||
errExpected: true,
|
||||
unsetError: true,
|
||||
client: &stubAWSS3StorageClient{getObjectErr: &types.NoSuchKey{}},
|
||||
wantErr: true,
|
||||
unsetError: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ func TestAWSS3Get(t *testing.T) {
|
|||
}
|
||||
|
||||
out, err := store.Get(context.Background(), "test-key")
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
|
||||
if tc.unsetError {
|
||||
|
@ -89,15 +89,15 @@ func TestAWSS3Get(t *testing.T) {
|
|||
|
||||
func TestAWSS3Put(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
client *stubAWSS3StorageClient
|
||||
errExpected bool
|
||||
client *stubAWSS3StorageClient
|
||||
wantErr bool
|
||||
}{
|
||||
"Put successful": {
|
||||
client: &stubAWSS3StorageClient{},
|
||||
},
|
||||
"PutObject fails": {
|
||||
client: &stubAWSS3StorageClient{putObjectErr: errors.New("error")},
|
||||
errExpected: true,
|
||||
client: &stubAWSS3StorageClient{putObjectErr: errors.New("error")},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ func TestAWSS3Put(t *testing.T) {
|
|||
testData := []byte{0x1, 0x2, 0x3}
|
||||
|
||||
err := store.Put(context.Background(), "test-key", testData)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
@ -124,23 +124,23 @@ func TestAWSS3Put(t *testing.T) {
|
|||
|
||||
func TestAWSS3CreateBucket(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
client *stubAWSS3StorageClient
|
||||
errExpected bool
|
||||
client *stubAWSS3StorageClient
|
||||
wantErr bool
|
||||
}{
|
||||
"CreateBucket successful": {
|
||||
client: &stubAWSS3StorageClient{},
|
||||
},
|
||||
"CreateBucket fails": {
|
||||
client: &stubAWSS3StorageClient{createBucketErr: errors.New("error")},
|
||||
errExpected: true,
|
||||
client: &stubAWSS3StorageClient{createBucketErr: errors.New("error")},
|
||||
wantErr: true,
|
||||
},
|
||||
"CreateBucket fails with BucketAlreadyExists": {
|
||||
client: &stubAWSS3StorageClient{createBucketErr: &types.BucketAlreadyExists{}},
|
||||
errExpected: false,
|
||||
client: &stubAWSS3StorageClient{createBucketErr: &types.BucketAlreadyExists{}},
|
||||
wantErr: false,
|
||||
},
|
||||
"CreateBucket fails with BucketAlreadyOwnedByYou": {
|
||||
client: &stubAWSS3StorageClient{createBucketErr: &types.BucketAlreadyOwnedByYou{}},
|
||||
errExpected: false,
|
||||
client: &stubAWSS3StorageClient{createBucketErr: &types.BucketAlreadyOwnedByYou{}},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ func TestAWSS3CreateBucket(t *testing.T) {
|
|||
}
|
||||
|
||||
err := store.createBucket(context.Background(), "test-bucket", "test-region")
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
|
@ -59,9 +59,9 @@ func TestAzureGet(t *testing.T) {
|
|||
someErr := errors.New("error")
|
||||
|
||||
testCases := map[string]struct {
|
||||
client stubAzureContainerAPI
|
||||
unsetError bool
|
||||
errExpected bool
|
||||
client stubAzureContainerAPI
|
||||
unsetError bool
|
||||
wantErr bool
|
||||
}{
|
||||
"success": {
|
||||
client: stubAzureContainerAPI{
|
||||
|
@ -69,14 +69,14 @@ func TestAzureGet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
"creating client fails": {
|
||||
client: stubAzureContainerAPI{newClientErr: someErr},
|
||||
errExpected: true,
|
||||
client: stubAzureContainerAPI{newClientErr: someErr},
|
||||
wantErr: true,
|
||||
},
|
||||
"DownloadBlobToBuffer fails": {
|
||||
client: stubAzureContainerAPI{
|
||||
blockBlobAPI: stubAzureBlockBlobAPI{downloadBlobToWriterAtErr: someErr},
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"BlobNotFound error": {
|
||||
client: stubAzureContainerAPI{
|
||||
|
@ -86,8 +86,8 @@ func TestAzureGet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
unsetError: true,
|
||||
errExpected: true,
|
||||
unsetError: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ func TestAzureGet(t *testing.T) {
|
|||
}
|
||||
|
||||
out, err := client.Get(context.Background(), "test-key")
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
|
||||
if tc.unsetError {
|
||||
|
@ -124,21 +124,21 @@ func TestAzurePut(t *testing.T) {
|
|||
someErr := errors.New("error")
|
||||
|
||||
testCases := map[string]struct {
|
||||
client stubAzureContainerAPI
|
||||
errExpected bool
|
||||
client stubAzureContainerAPI
|
||||
wantErr bool
|
||||
}{
|
||||
"success": {
|
||||
client: stubAzureContainerAPI{},
|
||||
},
|
||||
"creating client fails": {
|
||||
client: stubAzureContainerAPI{newClientErr: someErr},
|
||||
errExpected: true,
|
||||
client: stubAzureContainerAPI{newClientErr: someErr},
|
||||
wantErr: true,
|
||||
},
|
||||
"Upload fails": {
|
||||
client: stubAzureContainerAPI{
|
||||
blockBlobAPI: stubAzureBlockBlobAPI{uploadErr: someErr},
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ func TestAzurePut(t *testing.T) {
|
|||
}
|
||||
|
||||
err := client.Put(context.Background(), "test-key", testData)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
@ -170,8 +170,8 @@ func TestAzurePut(t *testing.T) {
|
|||
func TestCreateContainerOrContinue(t *testing.T) {
|
||||
someErr := errors.New("error")
|
||||
testCases := map[string]struct {
|
||||
client stubAzureContainerAPI
|
||||
errExpected bool
|
||||
client stubAzureContainerAPI
|
||||
wantErr bool
|
||||
}{
|
||||
"success": {
|
||||
client: stubAzureContainerAPI{},
|
||||
|
@ -180,12 +180,12 @@ func TestCreateContainerOrContinue(t *testing.T) {
|
|||
client: stubAzureContainerAPI{createErr: &azblob.StorageError{ErrorCode: azblob.StorageErrorCodeContainerAlreadyExists}},
|
||||
},
|
||||
"creating client fails": {
|
||||
client: stubAzureContainerAPI{newClientErr: someErr},
|
||||
errExpected: true,
|
||||
client: stubAzureContainerAPI{newClientErr: someErr},
|
||||
wantErr: true,
|
||||
},
|
||||
"Create fails": {
|
||||
client: stubAzureContainerAPI{createErr: someErr},
|
||||
errExpected: true,
|
||||
client: stubAzureContainerAPI{createErr: someErr},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ func TestCreateContainerOrContinue(t *testing.T) {
|
|||
}
|
||||
|
||||
err := client.createContainerOrContinue(context.Background())
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
|
@ -66,25 +66,25 @@ func TestGCPGet(t *testing.T) {
|
|||
someErr := errors.New("error")
|
||||
|
||||
testCases := map[string]struct {
|
||||
client *stubGCPStorageAPI
|
||||
unsetError bool
|
||||
errExpected bool
|
||||
client *stubGCPStorageAPI
|
||||
unsetError bool
|
||||
wantErr bool
|
||||
}{
|
||||
"success": {
|
||||
client: &stubGCPStorageAPI{newReaderOutput: []byte("test-data")},
|
||||
},
|
||||
"creating client fails": {
|
||||
client: &stubGCPStorageAPI{newClientErr: someErr},
|
||||
errExpected: true,
|
||||
client: &stubGCPStorageAPI{newClientErr: someErr},
|
||||
wantErr: true,
|
||||
},
|
||||
"NewReader fails": {
|
||||
client: &stubGCPStorageAPI{newReaderErr: someErr},
|
||||
errExpected: true,
|
||||
client: &stubGCPStorageAPI{newReaderErr: someErr},
|
||||
wantErr: true,
|
||||
},
|
||||
"ErrObjectNotExist error": {
|
||||
client: &stubGCPStorageAPI{newReaderErr: storage.ErrObjectNotExist},
|
||||
unsetError: true,
|
||||
errExpected: true,
|
||||
client: &stubGCPStorageAPI{newReaderErr: storage.ErrObjectNotExist},
|
||||
unsetError: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ func TestGCPGet(t *testing.T) {
|
|||
}
|
||||
|
||||
out, err := client.Get(context.Background(), "test-key")
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
|
||||
if tc.unsetError {
|
||||
|
@ -119,9 +119,9 @@ func TestGCPGet(t *testing.T) {
|
|||
func TestGCPPut(t *testing.T) {
|
||||
someErr := errors.New("error")
|
||||
testCases := map[string]struct {
|
||||
client *stubGCPStorageAPI
|
||||
unsetError bool
|
||||
errExpected bool
|
||||
client *stubGCPStorageAPI
|
||||
unsetError bool
|
||||
wantErr bool
|
||||
}{
|
||||
"success": {
|
||||
client: &stubGCPStorageAPI{
|
||||
|
@ -131,8 +131,8 @@ func TestGCPPut(t *testing.T) {
|
|||
},
|
||||
},
|
||||
"creating client fails": {
|
||||
client: &stubGCPStorageAPI{newClientErr: someErr},
|
||||
errExpected: true,
|
||||
client: &stubGCPStorageAPI{newClientErr: someErr},
|
||||
wantErr: true,
|
||||
},
|
||||
"NewWriter fails": {
|
||||
client: &stubGCPStorageAPI{
|
||||
|
@ -141,7 +141,7 @@ func TestGCPPut(t *testing.T) {
|
|||
writeErr: someErr,
|
||||
},
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ func TestGCPPut(t *testing.T) {
|
|||
testData := []byte{0x1, 0x2, 0x3}
|
||||
|
||||
err := client.Put(context.Background(), "test-key", testData)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
@ -172,7 +172,7 @@ func TestGCPCreateContainerOrContinue(t *testing.T) {
|
|||
testCases := map[string]struct {
|
||||
client *stubGCPStorageAPI
|
||||
createNewBucket bool
|
||||
errExpected bool
|
||||
wantErr bool
|
||||
}{
|
||||
"success": {
|
||||
client: &stubGCPStorageAPI{},
|
||||
|
@ -182,19 +182,19 @@ func TestGCPCreateContainerOrContinue(t *testing.T) {
|
|||
createNewBucket: true,
|
||||
},
|
||||
"creating client fails": {
|
||||
client: &stubGCPStorageAPI{newClientErr: someErr},
|
||||
errExpected: true,
|
||||
client: &stubGCPStorageAPI{newClientErr: someErr},
|
||||
wantErr: true,
|
||||
},
|
||||
"Attrs fails": {
|
||||
client: &stubGCPStorageAPI{attrsErr: someErr},
|
||||
errExpected: true,
|
||||
client: &stubGCPStorageAPI{attrsErr: someErr},
|
||||
wantErr: true,
|
||||
},
|
||||
"CreateBucket fails": {
|
||||
client: &stubGCPStorageAPI{
|
||||
attrsErr: storage.ErrBucketNotExist,
|
||||
createBucketErr: someErr,
|
||||
},
|
||||
errExpected: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ func TestGCPCreateContainerOrContinue(t *testing.T) {
|
|||
}
|
||||
|
||||
err := client.createContainerOrContinue(context.Background(), nil)
|
||||
if tc.errExpected {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue