From 5c370cf8013765d9e0f195925611e5e932ab71cd Mon Sep 17 00:00:00 2001 From: Abirdcfly Date: Wed, 10 Aug 2022 15:25:07 +0800 Subject: [PATCH] refactor: TestBlockingTags Signed-off-by: Abirdcfly --- internal/secret/restricted/store_test.go | 38 ++++++++++-------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/internal/secret/restricted/store_test.go b/internal/secret/restricted/store_test.go index 822d39088b..150f4b5b7d 100644 --- a/internal/secret/restricted/store_test.go +++ b/internal/secret/restricted/store_test.go @@ -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 { @@ -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()) } }) }