-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
230 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package v1beta1 | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func newNotificationTemplate(name string, editable *bool) *GrafanaNotificationTemplate { | ||
return &GrafanaNotificationTemplate{ | ||
TypeMeta: v1.TypeMeta{ | ||
APIVersion: APIVersion, | ||
Kind: "GrafanaNotificationTemplate", | ||
}, | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: name, | ||
Namespace: "default", | ||
}, | ||
Spec: GrafanaNotificationTemplateSpec{ | ||
Editable: editable, | ||
GrafanaCommonSpec: GrafanaCommonSpec{ | ||
InstanceSelector: &v1.LabelSelector{ | ||
MatchLabels: map[string]string{ | ||
"test": "notificationtemplate", | ||
}, | ||
}, | ||
}, | ||
Name: name, | ||
Template: "mock template", | ||
}, | ||
} | ||
} | ||
|
||
var _ = Describe("NotificationTemplate type", func() { | ||
Context("Ensure NotificationTemplate spec.editable is immutable", func() { | ||
ctx := context.Background() | ||
refTrue := true | ||
refFalse := false | ||
|
||
It("Should block adding editable field when missing", func() { | ||
notificationtemplate := newNotificationTemplate("missing-editable", nil) | ||
By("Create new NotificationTemplate without editable") | ||
Expect(k8sClient.Create(ctx, notificationtemplate)).To(Succeed()) | ||
|
||
By("Adding a editable") | ||
notificationtemplate.Spec.Editable = &refTrue | ||
Expect(k8sClient.Update(ctx, notificationtemplate)).To(HaveOccurred()) | ||
}) | ||
|
||
It("Should block removing editable field when set", func() { | ||
notificationtemplate := newNotificationTemplate("existing-editable", &refTrue) | ||
By("Creating NotificationTemplate with existing editable") | ||
Expect(k8sClient.Create(ctx, notificationtemplate)).To(Succeed()) | ||
|
||
By("And setting editable to ''") | ||
notificationtemplate.Spec.Editable = nil | ||
Expect(k8sClient.Update(ctx, notificationtemplate)).To(HaveOccurred()) | ||
}) | ||
|
||
It("Should block changing value of editable", func() { | ||
notificationtemplate := newNotificationTemplate("removing-editable", &refTrue) | ||
By("Create new NotificationTemplate with existing editable") | ||
Expect(k8sClient.Create(ctx, notificationtemplate)).To(Succeed()) | ||
|
||
By("Changing the existing editable") | ||
notificationtemplate.Spec.Editable = &refFalse | ||
Expect(k8sClient.Update(ctx, notificationtemplate)).To(HaveOccurred()) | ||
}) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.