Skip to content

Commit

Permalink
Add some great tests!
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Eckert committed Sep 23, 2021
1 parent ac54056 commit 5f2cb60
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

load _helpers

@test "autogenEncryption/Job: disabled by default" {
@test "gossipEncryptionAutogeneration/Job: disabled by default" {
cd `chart_dir`
assert_empty helm template \
-s templates/gossip-encryption-autogen-job.yaml \
.
}

@test "autogenEncryption/Job: enabled with global.gossipEncryption.autoGenerate=true" {
@test "gossipEncryptionAutogeneration/Job: enabled with global.gossipEncryption.autoGenerate=true" {
cd `chart_dir`
local actual=$(helm template \
-s templates/gossip-encryption-autogen-job.yaml \
Expand All @@ -19,15 +19,15 @@ load _helpers
[ "${actual}" = "true" ]
}

@test "autogenEncryption/Job: disabled when global.gossipEncryption.autoGenerate=false" {
@test "gossipEncryptionAutogeneration/Job: disabled when global.gossipEncryption.autoGenerate=false" {
cd `chart_dir`
assert_empty helm template \
-s templates/gossip-encryption-autogen-job.yaml \
--set 'global.gossipEncryption.autoGenerate=false' \
.
}

@test "autogenEncryption/Job: fails if global.gossipEncryption.autoGenerate=true and global.gossipEncryption.secretName and global.gossipEncryption.secretKey are set" {
@test "gossipEncryptionAutogeneration/Job: fails if global.gossipEncryption.autoGenerate=true and global.gossipEncryption.secretName and global.gossipEncryption.secretKey are set" {
cd `chart_dir`
run helm template \
-s templates/gossip-encryption-autogen-job.yaml \
Expand All @@ -39,7 +39,7 @@ load _helpers
[[ "$output" =~ "If global.gossipEncryption.autoGenerate is true, global.gossipEncryption.secretName and global.gossipEncryption.secretKey must not be set." ]]
}

@test "autogenEncryption/Job: fails if global.gossipEncryption.autoGenerate=true and global.gossipEncryption.secretName are set" {
@test "gossipEncryptionAutogeneration/Job: fails if global.gossipEncryption.autoGenerate=true and global.gossipEncryption.secretName are set" {
cd `chart_dir`
run helm template \
-s templates/gossip-encryption-autogen-job.yaml \
Expand All @@ -50,7 +50,7 @@ load _helpers
[[ "$output" =~ "If global.gossipEncryption.autoGenerate is true, global.gossipEncryption.secretName and global.gossipEncryption.secretKey must not be set." ]]
}

@test "autogenEncryption/Job: fails if global.gossipEncryption.autoGenerate=true and global.gossipEncryption.secretKey are set" {
@test "gossipEncryptionAutogeneration/Job: fails if global.gossipEncryption.autoGenerate=true and global.gossipEncryption.secretKey are set" {
cd `chart_dir`
run helm template \
-s templates/gossip-encryption-autogen-job.yaml \
Expand All @@ -62,7 +62,7 @@ load _helpers
}


@test "autogenEncryption/Job: secretName and secretKey are generated" {
@test "gossipEncryptionAutogeneration/Job: secretName and secretKey are generated" {
cd `chart_dir`
local actual=$(helm template \
-s templates/gossip-encryption-autogen-job.yaml \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bats

load _helpers

@test "gossipEncryptionAutogeneration/PodSecurityPolicy: disabled by default" {
cd `chart_dir`
assert_empty helm template \
-s templates/gossip-encryption-autogeneration-podsecuritypolicy.yaml \
.
}

@test "gossipEncryptionAutogeneration/PodSecurityPolicy: disabled with global.gossipEncryption.autoGenerate=false" {
cd `chart_dir`
assert_empty helm template \
-s templates/gossip-encryption-autogeneration-podsecuritypolicy.yaml \
--set 'global.gossipEncryption.autoGenerate=false' \
.
}

@test "gossipEncryptionAutogeneration/PodSecurityPolicy: enabled with global.gossipEncryption.autoGenerate=test" {
cd `chart_dir`
local actual=$(helm template \
-s templates/gossip-encryption-autogeneration-podsecuritypolicy.yaml \
--set 'global.gossipEncryption.autoGenerate=true' \
. | tee /dev/stderr |
yq -s 'length > 0' | tee /dev/stderr)
[ "${actual}" = "true" ]
}
28 changes: 28 additions & 0 deletions charts/consul/test/unit/gossip-encryption-autogeneration-role.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bats

load _helpers

@test "gossipEncryptionAutogeneration/Role: disabled by default" {
cd `chart_dir`
assert_empty helm template \
-s templates/gossip-encryption-autogeneration-role.yaml \
.
}

@test "gossipEncryptionAutogeneration/Role: disabled with global.gossipEncryption.autoGenerate=false" {
cd `chart_dir`
assert_empty helm template \
-s templates/gossip-encryption-autogeneration-role.yaml \
--set 'global.gossipEncryption.autoGenerate=false' \
.
}

@test "gossipEncryptionAutogeneration/Role: enabled when global.gossipEncryption.autoGenerate=true" {
cd `chart_dir`
local actual=$(helm template \
-s templates/gossip-encryption-autogeneration-role.yaml \
--set 'global.gossipEncryption.autoGenerate=true' \
. | tee /dev/stderr |
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "true" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

#!/usr/bin/env bats

load _helpers

@test "gossipEncryptionAutogeneration/RoleBinding: disabled by default" {
cd `chart_dir`
assert_empty helm template \
-s templates/gossip-encryption-autogeneration-rolebinding.yaml \
.
}

@test "gossipEncryptionAutogeneration/RoleBinding: disabled with global.gossipEncryption.autoGenerate=false" {
cd `chart_dir`
assert_empty helm template \
-s templates/gossip-encryption-autogeneration-rolebinding.yaml \
--set 'global.gossipEncryption.autoGenerate=false' \
.
}

@test "gossipEncryptionAutogeneration/RoleBinding: enabled with global.gossipEncryption.autoGenerate=true" {
cd `chart_dir`
local actual=$(helm template \
-s templates/gossip-encryption-autogeneration-rolebinding.yaml \
--set 'global.gossipEncryption.autoGenerate=true' \
. | tee /dev/stderr |
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "true" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bats

load _helpers

@test "gossipEncryptionAutogeneration/ServiceAccount: disabled by default" {
cd `chart_dir`
assert_empty helm template \
-s templates/gossip-encryption-autogeneration-serviceaccount.yaml \
.
}

@test "gossipEncryptionAutogeneration/ServiceAccount: disabled with global.gossipEncryption.autoGenerate=false" {
cd `chart_dir`
assert_empty helm template \
-s templates/gossip-encryption-autogeneration-serviceaccount.yaml \
--set 'global.gossipEncryption.autoGenerate=false' \
.
}

@test "gossipEncryptionAutogeneration/ServiceAccount: enabled with global.gossipEncryption.autoGenerate=true" {
cd `chart_dir`
local actual=$(helm template \
-s templates/gossip-encryption-autogeneration-serviceaccount.yaml \
--set 'global.gossipEncryption.autoGenerate=true' \
. | tee /dev/stderr |
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# global.imagePullSecrets

@test "gossipEncryptionAutogeneration/ServiceAccount: can set image pull secrets" {
cd `chart_dir`
local object=$(helm template \
-s templates/gossip-encryption-autogeneration-serviceaccount.yaml \
--set 'global.gossipEncryption.autoGenerate=true' \
--set 'global.imagePullSecrets[0].name=my-secret' \
--set 'global.imagePullSecrets[1].name=my-secret2' \
. | tee /dev/stderr)

local actual=$(echo "$object" |
yq -r '.imagePullSecrets[0].name' | tee /dev/stderr)
[ "${actual}" = "my-secret" ]

local actual=$(echo "$object" |
yq -r '.imagePullSecrets[1].name' | tee /dev/stderr)
[ "${actual}" = "my-secret2" ]
}

0 comments on commit 5f2cb60

Please sign in to comment.