Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
navid.shariaty committed Oct 28, 2023
1 parent 04d6bd5 commit fa8efb3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions api/v1alpha1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var cancel context.CancelFunc

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Webhook Suite", []Reporter{})
}

var _ = BeforeSuite(func() {
Expand Down
1 change: 1 addition & 0 deletions config/samples/_v1alpha1_agesecret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
namespace: test-age-secret
labels:
key_label: value_label
app.kubernetes.io/instance: this-should-be-removed
annotations:
key_annotation: value_annotation
spec:
Expand Down
18 changes: 14 additions & 4 deletions controllers/agesecret_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var (
fooValidAgeKeyPath3 = filepath.Join("..", "config", "samples", "_v1alpha1_agekey3.yaml")
fooValidAgeKeyPath2 = filepath.Join("..", "config", "samples", "_v1alpha1_agekey2.yaml")
fooValidAgeSecretPath = filepath.Join("..", "config", "samples", "_v1alpha1_agesecret.yaml")

unwantedLabel = "app.kubernetes.io/instance"
)

var _ = Describe("", func() {
Expand Down Expand Up @@ -74,8 +76,16 @@ var _ = Describe("", func() {
fooSecretObj := &corev1.Secret{}
err = k8sClient.Get(ctx, types.NamespacedName{Namespace: validAgeSecretObj.Namespace, Name: validAgeSecretObj.Name}, fooSecretObj)
Expect(err).To(BeNil())
Expect(fooSecretObj.GetLabels()).Should(Equal(validAgeSecretObj.GetLabels()))
Expect(fooSecretObj.GetAnnotations()).Should(Equal(validAgeSecretObj.GetAnnotations()))
// check unwanted label to be removed
unwantedLabelExists := false
secretLabels := fooSecretObj.GetLabels()
for _, label := range secretLabels {
if label == unwantedLabel {
unwantedLabelExists = true
}
}
Expect(unwantedLabelExists).To(BeFalse())

sampleKeyValue, exists := fooSecretObj.Data["sample_key"]
Expect(string(sampleKeyValue)).Should(Equal("sample_value"))
Expand All @@ -86,9 +96,9 @@ var _ = Describe("", func() {
Expect(exists).To(BeTrue())

// Remove secret, it should be created again
err = k8sClient.Delete(ctx, fooSecretObj)
err = k8sClient.Get(ctx, types.NamespacedName{Namespace: validAgeSecretObj.Namespace, Name: validAgeSecretObj.Name}, fooSecretObj)
Expect(err).To(BeNil())
//err = k8sClient.Delete(ctx, fooSecretObj)
//err = k8sClient.Get(ctx, types.NamespacedName{Namespace: validAgeSecretObj.Namespace, Name: validAgeSecretObj.Name}, fooSecretObj)
//Expect(err).To(BeNil())

err = k8sClient.Delete(ctx, validAgeKeyObj)
Expect(err).To(BeNil())
Expand Down
1 change: 1 addition & 0 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var testEnv *envtest.Environment

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Webhook Suite", []Reporter{})
}

var _ = BeforeSuite(func() {
Expand Down

0 comments on commit fa8efb3

Please sign in to comment.