Skip to content

Commit

Permalink
test: initial tests for config loader (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
devshawn authored Oct 29, 2020
1 parent c7e9ac7 commit 57a12ed
Showing 1 changed file with 49 additions and 0 deletions.
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\";"
}


}

0 comments on commit 57a12ed

Please sign in to comment.