Skip to content

Commit

Permalink
Add annotation utils to space and nstemplateset test utils (#409)
Browse files Browse the repository at this point in the history
* Add annotation utils to space and nstemplateset test utils

* More
  • Loading branch information
alexeykazakov authored Jun 28, 2024
1 parent 7ec2869 commit d42111e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/test/nstemplateset/nstemplateset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
15 changes: 15 additions & 0 deletions pkg/test/nstemplateset/nstemplateset_assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions pkg/test/space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
15 changes: 15 additions & 0 deletions pkg/test/space/space_assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d42111e

Please sign in to comment.