-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: initial tests for config loader (#45)
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/test/groovy/com/devshawn/kafka/gitops/config/KafkaGitopsConfigLoaderSpec.groovy
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,49 @@ | ||
package com.devshawn.kafka.gitops.config | ||
|
||
|
||
import org.apache.kafka.common.config.SaslConfigs | ||
import org.junit.ClassRule | ||
import org.junit.contrib.java.lang.system.EnvironmentVariables | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
|
||
class KafkaGitopsConfigLoaderSpec extends Specification { | ||
|
||
@Shared | ||
@ClassRule | ||
EnvironmentVariables environmentVariables | ||
|
||
void setupSpec() { | ||
environmentVariables.set("KAFKA_BOOTSTRAP_SERVERS", "localhost:9092") | ||
environmentVariables.set("KAFKA_SASL_MECHANISM", "PLAIN") | ||
environmentVariables.set("KAFKA_SECURITY_PROTOCOL", "SASL_PLAINTEXT") | ||
} | ||
|
||
void 'test username and password shortcut'() { | ||
setup: | ||
environmentVariables.set("KAFKA_SASL_JAAS_USERNAME", "test") | ||
environmentVariables.set("KAFKA_SASL_JAAS_PASSWORD", "test-secret") | ||
|
||
when: | ||
KafkaGitopsConfig config = KafkaGitopsConfigLoader.load() | ||
|
||
then: | ||
config | ||
config.config.get(SaslConfigs.SASL_JAAS_CONFIG) == "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"test\" password=\"test-secret\";" | ||
} | ||
|
||
void 'test escaping username and password shortcut'() { | ||
setup: | ||
environmentVariables.set("KAFKA_SASL_JAAS_USERNAME", "te\"st") | ||
environmentVariables.set("KAFKA_SASL_JAAS_PASSWORD", "te\"st-secr\"et") | ||
|
||
when: | ||
KafkaGitopsConfig config = KafkaGitopsConfigLoader.load() | ||
|
||
then: | ||
config | ||
config.config.get(SaslConfigs.SASL_JAAS_CONFIG) == "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"te\\\"st\" password=\"te\\\"st-secr\\\"et\";" | ||
} | ||
|
||
|
||
} |