Skip to content

Commit

Permalink
merge(#3627): refactor TestBlockingTags
Browse files Browse the repository at this point in the history
  • Loading branch information
akijakya authored Aug 15, 2022
2 parents 9bf4a91 + 5c370cf commit 96c12e0
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions internal/secret/restricted/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ const (

func TestBlockingTags(t *testing.T) {
cases := []struct {
name string
request *secret.CreateSecretRequest
name string
request *secret.CreateSecretRequest
expectErr error
}{
{name: "readonly", request: &requestReadOnly},
{name: "forbidden", request: &requestForbidden},
{name: "readonly", request: &requestReadOnly, expectErr: ReadOnlyError{SecretID: secret.GenerateSecretID(&requestReadOnly)}},
{name: "forbidden", request: &requestForbidden, expectErr: ForbiddenError{ForbiddenTag: secret.TagKubeConfig}},
}

for _, tc := range cases {
Expand All @@ -45,28 +46,21 @@ func TestBlockingTags(t *testing.T) {

secretID, err := store.Store(orgID, tc.request)
if err != nil {
t.Errorf("error during storing readonly secret: %s", err.Error())
t.FailNow()
t.Fatalf("error during storing readonly secret: %s", err.Error())
}

err = store.Delete(orgID, secretID)
if err == nil {
t.Error("readonly secret deleted..")
t.FailNow()

tc.request.Tags = append(tc.request.Tags, "newtag")

err = store.Update(orgID, secretID, tc.request)
if err == nil {
t.Error("readonly secret updated..")
t.FailNow()
}

expErr := ReadOnlyError{SecretID: secretID}
if !reflect.DeepEqual(err, expErr) {
t.Errorf("expected error: %s, got: %s", expErr, err.Error())
t.FailNow()
}
t.Fatalf("readonly secret deleted..")
}

err = store.Update(orgID, secretID, tc.request)
if err == nil {
t.Fatalf("readonly secret updated..")
}

if !reflect.DeepEqual(err, tc.expectErr) {
t.Fatalf("expected error: %s, got: %s", tc.expectErr, err.Error())
}
})
}
Expand Down

0 comments on commit 96c12e0

Please sign in to comment.