Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: TestBlockingTags #3627

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially, this test was found to be faulty because the subsequent code was unreachable because of t.FailNow() in line 55, and during the modification process, it was found that the test should be refactored directly


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