Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gkrenn committed Nov 22, 2024
1 parent 659c133 commit 8b6bcde
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
9 changes: 7 additions & 2 deletions pkg/controllers/dynakube/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
TokenReadyConditionMessage = "Token ready"
TokenWithoutDataIngestConditionMessage = "Token ready, DataIngest token not provided"
)

func (controller *Controller) setConditionTokenError(dk *dynakube.DynaKube, err error) {
tokenErrorCondition := metav1.Condition{
Type: dynakube.TokenConditionType,
Expand All @@ -18,9 +23,9 @@ func (controller *Controller) setConditionTokenError(dk *dynakube.DynaKube, err
}

func (controller *Controller) setConditionTokenReady(dk *dynakube.DynaKube, dataIngestTokenProvided bool) {
msg := "Token ready, DataIngest token not provided"
msg := TokenWithoutDataIngestConditionMessage
if dataIngestTokenProvided {
msg = "Token ready"
msg = TokenReadyConditionMessage
}

tokenErrorCondition := metav1.Condition{
Expand Down
22 changes: 21 additions & 1 deletion pkg/controllers/dynakube/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,27 @@ func TestTokenConditions(t *testing.T) {
_, err := controller.setupTokensAndClient(ctx, dk)

require.NoError(t, err)
assertCondition(t, dk, dynakube.TokenConditionType, metav1.ConditionTrue, dynakube.ReasonTokenReady, "")
assertCondition(t, dk, dynakube.TokenConditionType, metav1.ConditionTrue, dynakube.ReasonTokenReady, TokenWithoutDataIngestConditionMessage)

fakeClient = fake.NewClient(&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testNamespace,
},
Data: map[string][]byte{
dtclient.ApiToken: []byte(testAPIToken),
dtclient.DataIngestToken: []byte(testAPIToken),
},
})
controller = &Controller{
client: fakeClient,
apiReader: fakeClient,
dynatraceClientBuilder: mockDtcBuilder,
}
_, err = controller.setupTokensAndClient(ctx, dk)

require.NoError(t, err)
assertCondition(t, dk, dynakube.TokenConditionType, metav1.ConditionTrue, dynakube.ReasonTokenReady, TokenReadyConditionMessage)
})
}

Expand Down

0 comments on commit 8b6bcde

Please sign in to comment.