Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ybelMekk committed Sep 22, 2021
1 parent 14aa854 commit 4203487
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 109 deletions.
45 changes: 23 additions & 22 deletions pkg/config/kafka_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,45 @@ import (
func TestKafkaEnvironmentConfigGenerated(t *testing.T) {

var envKeys = []string{
consts.KafkaCertificate,
consts.KafkaCa,
consts.KafkaPrivateKey,
consts.KafkaClientKeystoreP12,
consts.KafkaClientTruststoreJks,
consts.KafkaCredStorePassword,
consts.KafkaSchemaRegistry,
consts.KafkaCAKey,
consts.KafkaCertificateKey,
consts.KafkaPrivateKeyKey,
consts.KafkaClientKeyStoreP12File,
consts.KafkaClientTruststoreJksFile,
consts.KafkaCredStorePasswordKey,
consts.KafkaSchemaRegistryKey,
}

tmpDest := test.SetupDest(t)
kcatConfig := NewEnvConfig(test.SetupSecret(envKeys), KafkaConfigEnvToFileMap, tmpDest)
kcatConfig := NewEnvConfig(test.SetupSecret(envKeys), tmpDest)

result, err := kcatConfig.Generate()
assert.NoError(t, err)

assert.True(t, strings.Contains(result, "client.truststore.jks"))
assert.True(t, strings.Contains(result, "KAFKA_CREDSTORE_PASSWORD"))
assert.True(t, strings.Contains(result, "KAFKA_SCHEMA_REGISTRY"))
assert.True(t, strings.Contains(result, "KAFKA_CERTIFICATE"))
assert.True(t, strings.Contains(result, "KAFKA_CA"))
assert.True(t, strings.Contains(result, "KAFKA_PRIVATE_KEY"))
assert.True(t, strings.Contains(result, "client.keystore.p12"))
assert.True(t, strings.Contains(result, consts.KafkaClientTruststoreJksFile))
assert.True(t, strings.Contains(result, consts.KafkaCredStorePasswordKey))
assert.True(t, strings.Contains(result, consts.KafkaSchemaRegistryKey))
assert.True(t, strings.Contains(result, consts.KafkaCertificateKey))
assert.True(t, strings.Contains(result, consts.KafkaCAKey))
assert.True(t, strings.Contains(result, consts.KafkaPrivateKeyKey))
assert.True(t, strings.Contains(result, consts.KafkaClientKeyStoreP12File))

defer os.Remove(tmpDest)
}

func TestKafkaEnvironmentSecrettMissingRequiredData(t *testing.T) {

var envKeys = []string{
consts.KafkaCertificate,
consts.KafkaCa,
consts.KafkaPrivateKey,
consts.KafkaClientKeystoreP12,
consts.KafkaCredStorePassword,
consts.KafkaSchemaRegistry,
consts.KafkaCAKey,
consts.KafkaCertificateKey,
consts.KafkaPrivateKeyKey,
consts.KafkaClientKeyStoreP12File,
consts.KafkaCredStorePasswordKey,
consts.KafkaSchemaRegistryKey,
}

tmpDest := test.SetupDest(t)
kcatConfig := NewEnvConfig(test.SetupSecret(envKeys), KafkaConfigEnvToFileMap, tmpDest)
kcatConfig := NewEnvConfig(test.SetupSecret(envKeys), tmpDest)
_, err := kcatConfig.Generate()
assert.EqualError(t, err, "can not generate kafka-secret.env config, secret missing required key: client.truststore.jks")

Expand Down
31 changes: 15 additions & 16 deletions pkg/config/kcat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,37 @@ import (
func TestKcatConfigGenerated(t *testing.T) {

var envKeys = []string{
consts.KafkaCertificate,
consts.KafkaCa,
consts.KafkaPrivateKey,
consts.KafkaClientKeystoreP12,
consts.KafkaClientTruststoreJks,
consts.KafkaCredStorePassword,
consts.KafkaSchemaRegistry,
consts.KafkaCAKey,
consts.KafkaCertificateKey,
consts.KafkaPrivateKeyKey,
consts.KafkaClientKeyStoreP12File,
consts.KafkaClientTruststoreJksFile,
consts.KafkaCredStorePasswordKey,
consts.KafkaSchemaRegistryKey,
}

tmpDest := test.SetupDest(t)
kcatConfig := NewKCatConfig(test.SetupSecret(envKeys), KCatEnvToFileMap, tmpDest)
kcatConfig := NewKCatConfig(test.SetupSecret(envKeys), tmpDest)
result, err := kcatConfig.Generate()
assert.NoError(t, err)

assert.NoError(t, err)
assert.True(t, strings.Contains(result, "ssl.ca.location"))
assert.True(t, strings.Contains(result, "ssl.key.location"))
assert.True(t, strings.Contains(result, "ssl.certificate"))
assert.True(t, strings.Contains(result, "security.protocol"))
assert.True(t, strings.Contains(result, KafkaCatSslCaLocation))
assert.True(t, strings.Contains(result, KafkaCatSslKeyLocation))
assert.True(t, strings.Contains(result, KafkaCatSslCertificateLocation))
assert.True(t, strings.Contains(result, KafkaSecurityProtocolLocation))

defer os.Remove(tmpDest)
}

func TestKcatSecretMissingRequiredData(t *testing.T) {

var envKeys = []string{
consts.KafkaCertificate,
consts.KafkaCa,
consts.KafkaCAKey,
consts.KafkaCertificateKey,
}

tmpDest := test.SetupDest(t)
kcatConfig := NewKCatConfig(test.SetupSecret(envKeys), KCatEnvToFileMap, tmpDest)
kcatConfig := NewKCatConfig(test.SetupSecret(envKeys), tmpDest)
_, err := kcatConfig.Generate()
assert.EqualError(t, err, "can not generate kcat.conf config, secret missing required key: KAFKA_PRIVATE_KEY")

Expand Down
71 changes: 0 additions & 71 deletions pkg/secret/secret_test.go

This file was deleted.

0 comments on commit 4203487

Please sign in to comment.