-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue-639, integration tests for kafkauser controller
- Loading branch information
Bohdan Siryk
authored and
Bohdan Siryk
committed
Dec 11, 2023
1 parent
8dd9a0e
commit 9e94866
Showing
6 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
controllers/kafkamanagement/datatest/kafkauser_v1beta1.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: kafkamanagement.instaclustr.com/v1beta1 | ||
kind: KafkaUser | ||
metadata: | ||
name: kafkauser-test-sample | ||
namespace: default | ||
spec: | ||
secretRef: | ||
name: "secret-test-sample" | ||
namespace: "default" | ||
initialPermissions: "standard" | ||
overrideExistingUser: true | ||
saslScramMechanism: "SCRAM-SHA-256" | ||
authMechanism: "SASL" |
8 changes: 8 additions & 0 deletions
8
controllers/kafkamanagement/datatest/kafkauser_v1beta1_secret.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: secret-test-sample | ||
namespace: default | ||
data: | ||
username: "U2FuY2gtdHdvCg==" | ||
password: "Qm9oZGFuX3ViZXJfdW50ZXJfaWdvcl90b2xpazEK" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package kafkamanagement | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/util/yaml" | ||
|
||
"github.com/instaclustr/operator/apis/kafkamanagement/v1beta1" | ||
"github.com/instaclustr/operator/pkg/models" | ||
) | ||
|
||
var _ = Describe("Kafka User Controller", func() { | ||
secret := &v1.Secret{} | ||
kafkaUser := &v1beta1.KafkaUser{} | ||
|
||
b, err := os.ReadFile(filepath.Join(".", "datatest", "kafkauser_v1beta1.yaml")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = yaml.Unmarshal(b, kafkaUser) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
b, err = os.ReadFile(filepath.Join(".", "datatest", "kafkauser_v1beta1_secret.yaml")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = yaml.Unmarshal(b, secret) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
const testClusterID = "testClusterID" | ||
|
||
When("Apply kafka user manifest", func() { | ||
It("creates kafka user resource and waits until status is filled", func() { | ||
Expect(k8sClient.Create(ctx, secret)).Should(Succeed()) | ||
Expect(k8sClient.Create(ctx, kafkaUser)).Should(Succeed()) | ||
|
||
Expect(kafkaUser.Status.ClustersEvents).Should(BeEmpty()) | ||
}) | ||
}) | ||
|
||
When("Add kafka user reference in kafka cluster resource", func() { | ||
It("should create user for the given cluster", func() { | ||
patch := kafkaUser.NewPatch() | ||
kafkaUser.Status.ClustersEvents = map[string]string{ | ||
testClusterID: models.CreatingEvent, | ||
} | ||
|
||
Expect(k8sClient.Status().Patch(ctx, kafkaUser, patch)).Should(Succeed()) | ||
|
||
Expect(kafkaUser.Status.ClustersEvents).ShouldNot(BeEmpty()) | ||
|
||
Eventually(func(g Gomega) { | ||
g.Expect(kafkaUser.Status.ClustersEvents[testClusterID]).Should(Or( | ||
Equal(models.Created), | ||
Equal(models.UpdatedEvent), | ||
)) | ||
}, timeout, interval) | ||
}) | ||
}) | ||
|
||
When("Remove kafka user reference from kafka cluster resource", func() { | ||
It("should delete user from the given cluster", func() { | ||
patch := kafkaUser.NewPatch() | ||
kafkaUser.Status.ClustersEvents = map[string]string{ | ||
testClusterID: models.DeletingEvent, | ||
} | ||
|
||
Expect(k8sClient.Status().Patch(ctx, kafkaUser, patch)).Should(Succeed()) | ||
|
||
Eventually(func(g Gomega) { | ||
g.Expect(kafkaUser.Status.ClustersEvents).Should(BeEmpty()) | ||
}, timeout, interval) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters