Skip to content

Commit

Permalink
Add target cluster option to social event test util (#424)
Browse files Browse the repository at this point in the history
* Add target cluster option to social event test util

* replace

* Update pkg/test/socialevent/socialevent_test.go

Co-authored-by: Rajiv Senthilnathan <[email protected]>

* default test

---------

Co-authored-by: Rajiv Senthilnathan <[email protected]>
  • Loading branch information
alexeykazakov and rajivnathan authored Aug 16, 2024
1 parent a209f6c commit 2184e62
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/codeready-toolchain/toolchain-common
go 1.20

require (
github.com/codeready-toolchain/api v0.0.0-20240802163003-cce070815e69
github.com/codeready-toolchain/api v0.0.0-20240815232340-d0c164a83d27
github.com/go-logr/logr v1.2.3
github.com/golang-jwt/jwt/v5 v5.2.0
github.com/lestrrat-go/jwx v1.2.29
Expand All @@ -30,6 +30,7 @@ require (
github.com/google/go-github/v52 v52.0.0
github.com/google/uuid v1.6.0
github.com/migueleliasweb/go-github-mock v0.0.18
github.com/prometheus/client_golang v1.12.2
golang.org/x/oauth2 v0.7.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/kubectl v0.24.0
Expand Down Expand Up @@ -83,7 +84,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWH
github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo=
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/codeready-toolchain/api v0.0.0-20240802163003-cce070815e69 h1:e6up2k4O7QdG6hu0iOwNGap60b932N0JXlweDmmvCAQ=
github.com/codeready-toolchain/api v0.0.0-20240802163003-cce070815e69/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E=
github.com/codeready-toolchain/api v0.0.0-20240815232340-d0c164a83d27 h1:uEH8HAM81QZBccuqQpGKJUoJQe28+DFSYi/mRKZDYrA=
github.com/codeready-toolchain/api v0.0.0-20240815232340-d0c164a83d27/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down
6 changes: 6 additions & 0 deletions pkg/test/socialevent/socialevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ func WithMaxAttendees(value int) Option {
event.Spec.MaxAttendees = value
}
}

func WithTargetCluster(target string) Option {
return func(event *toolchainv1alpha1.SocialEvent) {
event.Spec.TargetCluster = target
}
}
16 changes: 16 additions & 0 deletions pkg/test/socialevent/socialevent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestNewSocialEvent(t *testing.T) {
assert.Equal(t, "base1ns", e.Spec.SpaceTier) // default
assert.Equal(t, 10, e.Spec.MaxAttendees) // default
assert.Equal(t, 0, e.Status.ActivationCount) // default
assert.Empty(t, e.Spec.TargetCluster) // default
})

t.Run("with custom user tier", func(t *testing.T) {
Expand All @@ -32,6 +33,7 @@ func TestNewSocialEvent(t *testing.T) {
assert.Equal(t, "base1ns", e.Spec.SpaceTier) // default
assert.Equal(t, 10, e.Spec.MaxAttendees) // default
assert.Equal(t, 0, e.Status.ActivationCount) // default
assert.Empty(t, e.Spec.TargetCluster) // default
})

t.Run("with custom space tier", func(t *testing.T) {
Expand All @@ -52,6 +54,7 @@ func TestNewSocialEvent(t *testing.T) {
assert.Equal(t, "base1ns", e.Spec.SpaceTier) // default
assert.Equal(t, 5, e.Spec.MaxAttendees) // custom
assert.Equal(t, 0, e.Status.ActivationCount) // default
assert.Empty(t, e.Spec.TargetCluster) // default
})

t.Run("with custom activation count", func(t *testing.T) {
Expand All @@ -62,6 +65,7 @@ func TestNewSocialEvent(t *testing.T) {
assert.Equal(t, "base1ns", e.Spec.SpaceTier) // default
assert.Equal(t, 10, e.Spec.MaxAttendees) // default
assert.Equal(t, 1, e.Status.ActivationCount) // custom
assert.Empty(t, e.Spec.TargetCluster) // default
})

t.Run("with custom start time", func(t *testing.T) {
Expand All @@ -75,6 +79,7 @@ func TestNewSocialEvent(t *testing.T) {
assert.Equal(t, 10, e.Spec.MaxAttendees) // default
assert.Equal(t, 0, e.Status.ActivationCount) // default
assert.Equal(t, metav1.NewTime(start), e.Spec.StartTime) // custom
assert.Empty(t, e.Spec.TargetCluster) // default
})

t.Run("with custom end time", func(t *testing.T) {
Expand All @@ -88,6 +93,17 @@ func TestNewSocialEvent(t *testing.T) {
assert.Equal(t, 10, e.Spec.MaxAttendees) // default
assert.Equal(t, 0, e.Status.ActivationCount) // default
assert.Equal(t, metav1.NewTime(end), e.Spec.EndTime) // custom
assert.Empty(t, e.Spec.TargetCluster) // default
})

t.Run("with custom target cluster", func(t *testing.T) {
// when
e := testsocialevent.NewSocialEvent(test.HostOperatorNs, socialevent.NewName(), testsocialevent.WithTargetCluster("member-1"))
// then
assert.Equal(t, "deactivate30", e.Spec.UserTier) // default
assert.Equal(t, "base1ns", e.Spec.SpaceTier) // default
assert.Equal(t, 10, e.Spec.MaxAttendees) // default
assert.Equal(t, 0, e.Status.ActivationCount) // default
assert.Equal(t, "member-1", e.Spec.TargetCluster) // custom
})
}

0 comments on commit 2184e62

Please sign in to comment.