Skip to content

Commit

Permalink
add a few helper functions for UserAccounts
Browse files Browse the repository at this point in the history
  • Loading branch information
MatousJobanek committed Sep 28, 2023
1 parent 0f59f17 commit 4d52ef0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/test/masteruserrecord/masteruserrecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ func AdditionalAccounts(clusters ...string) MurModifier {
}
}

func StatusUserAccount(cluster string, conditions ...toolchainv1alpha1.Condition) MurModifier {
return func(mur *toolchainv1alpha1.MasterUserRecord) error {
mur.Status.UserAccounts = append(mur.Status.UserAccounts, toolchainv1alpha1.UserAccountStatusEmbedded{
Cluster: toolchainv1alpha1.Cluster{
Name: cluster,
},
UserAccountStatus: toolchainv1alpha1.UserAccountStatus{
Conditions: conditions,
},
})
return nil
}
}

func TierName(tierName string) MurModifier {
return func(mur *toolchainv1alpha1.MasterUserRecord) error {
mur.Spec.TierName = tierName
Expand Down
13 changes: 13 additions & 0 deletions pkg/test/masteruserrecord/masteruserrecord_assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ func (a *MasterUserRecordAssertion) AllUserAccountsHaveCondition(expected toolch
return a
}

func (a *MasterUserRecordAssertion) HasStatusUserAccountsWithCondition(targetCluster string, expected toolchainv1alpha1.Condition) *MasterUserRecordAssertion {
err := a.loadMasterUserRecord()
require.NoError(a.t, err)
for _, ua := range a.mur.Status.UserAccounts {
if ua.Cluster.Name == targetCluster {
test.AssertConditionsMatch(a.t, ua.Conditions, expected)
return a
}
}
assert.Fail(a.t, "unable to find status UserAccount with the given targetCluster", "targetCluster", targetCluster)
return a
}

func (a *MasterUserRecordAssertion) HasTier(tier toolchainv1alpha1.UserTier) *MasterUserRecordAssertion {
err := a.loadMasterUserRecord()
require.NoError(a.t, err)
Expand Down
8 changes: 8 additions & 0 deletions pkg/test/useraccount/useraccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/codeready-toolchain/toolchain-common/pkg/condition"
"github.com/codeready-toolchain/toolchain-common/pkg/test"
"github.com/redhat-cop/operator-utils/pkg/util"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -62,3 +63,10 @@ func DeletedUa() UaModifier {
ua.DeletionTimestamp = &now
}
}

// WithFinalizer creates a UaModifier to add an finalizer on the UserAccount
func WithFinalizer() UaModifier {
return func(ua *toolchainv1alpha1.UserAccount) {
util.AddFinalizer(ua, toolchainv1alpha1.FinalizerName)
}
}

0 comments on commit 4d52ef0

Please sign in to comment.