diff --git a/pkg/test/nstemplateset/nstemplateset.go b/pkg/test/nstemplateset/nstemplateset.go index c41c8731..e7b5c5e0 100644 --- a/pkg/test/nstemplateset/nstemplateset.go +++ b/pkg/test/nstemplateset/nstemplateset.go @@ -122,3 +122,12 @@ func WithDeletionTimestamp(ts time.Time) Option { nstmplSet.DeletionTimestamp = &metav1.Time{Time: ts} } } + +func WithAnnotation(key, value string) Option { + return func(nstmplSet *toolchainv1alpha1.NSTemplateSet) { + if nstmplSet.ObjectMeta.Annotations == nil { + nstmplSet.ObjectMeta.Annotations = map[string]string{} + } + nstmplSet.ObjectMeta.Annotations[key] = value + } +} diff --git a/pkg/test/nstemplateset/nstemplateset_assertion.go b/pkg/test/nstemplateset/nstemplateset_assertion.go index 8fdb6d40..986a4d7b 100644 --- a/pkg/test/nstemplateset/nstemplateset_assertion.go +++ b/pkg/test/nstemplateset/nstemplateset_assertion.go @@ -142,6 +142,21 @@ func (a *Assertion) HasSpaceRoles(expectedSpaceRoles ...toolchainv1alpha1.NSTemp return a } +func (a *Assertion) HasAnnotationWithValue(key, value string) *Assertion { + err := a.loadNSTemplateSet() + require.NoError(a.t, err) + require.NotNil(a.t, a.nsTmplSet.Annotations) + assert.Equal(a.t, value, a.nsTmplSet.Annotations[key]) + return a +} + +func (a *Assertion) DoesNotHaveAnnotation(key string) *Assertion { + err := a.loadNSTemplateSet() + require.NoError(a.t, err) + require.NotContains(a.t, a.nsTmplSet.Annotations, key) + return a +} + func SpaceRole(templateRef string, usernames ...string) toolchainv1alpha1.NSTemplateSetSpaceRole { return toolchainv1alpha1.NSTemplateSetSpaceRole{ TemplateRef: templateRef, diff --git a/pkg/test/space/space.go b/pkg/test/space/space.go index cd04fec9..739f0671 100644 --- a/pkg/test/space/space.go +++ b/pkg/test/space/space.go @@ -60,6 +60,15 @@ func WithLabel(key, value string) Option { } } +func WithAnnotation(key, value string) Option { + return func(space *toolchainv1alpha1.Space) { + if space.ObjectMeta.Annotations == nil { + space.ObjectMeta.Annotations = map[string]string{} + } + space.ObjectMeta.Annotations[key] = value + } +} + func WithDefaultTier() Option { return func(space *toolchainv1alpha1.Space) { space.Spec.TierName = "" diff --git a/pkg/test/space/space_assertions.go b/pkg/test/space/space_assertions.go index 5a7396ab..47259b06 100644 --- a/pkg/test/space/space_assertions.go +++ b/pkg/test/space/space_assertions.go @@ -111,6 +111,21 @@ func (a *Assertion) HasLabelWithValue(key, value string) *Assertion { return a } +func (a *Assertion) HasAnnotationWithValue(key, value string) *Assertion { + err := a.loadResource() + require.NoError(a.t, err) + require.NotNil(a.t, a.space.Annotations) + assert.Equal(a.t, value, a.space.Annotations[key]) + return a +} + +func (a *Assertion) DoesNotHaveAnnotation(key string) *Assertion { + err := a.loadResource() + require.NoError(a.t, err) + require.NotContains(a.t, a.space.Annotations, key) + return a +} + func (a *Assertion) HasMatchingTierLabelForTier(tier *toolchainv1alpha1.NSTemplateTier) *Assertion { err := a.loadResource() require.NoError(a.t, err)