Skip to content

Commit

Permalink
fix chart unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Martens <[email protected]>
  • Loading branch information
JanMa committed Sep 4, 2024
1 parent b9bb151 commit 5acd951
Show file tree
Hide file tree
Showing 23 changed files with 55 additions and 155 deletions.
4 changes: 2 additions & 2 deletions test/acceptance/_helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ helm_install() {

helm install -f ${values} \
--name openbao \
${BATS_TEST_DIRNAME}/../..
${BATS_TEST_DIRNAME}/../../charts/openbao
}

# helm_install_ha installs the openbao chart using HA mode. This will source
Expand All @@ -40,7 +40,7 @@ helm_install_ha() {
--name openbao \
--set 'server.enabled=false' \
--set 'serverHA.enabled=true' \
${BATS_TEST_DIRNAME}/../..
${BATS_TEST_DIRNAME}/../../charts/openbao
}

# wait for consul to be ready
Expand Down
2 changes: 1 addition & 1 deletion test/unit/csi-clusterrole.bats
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ load _helpers
. | tee /dev/stderr |
yq -r '.metadata.name' | tee /dev/stderr)
[ "${actual}" = "release-name-openbao-csi-provider-clusterrole" ]
}
}
2 changes: 1 addition & 1 deletion test/unit/csi-clusterrolebinding.bats
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ load _helpers
. | tee /dev/stderr |
yq -r '.subjects[0].namespace' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}
}
2 changes: 1 addition & 1 deletion test/unit/csi-daemonset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ load _helpers

local actual=$(echo $object |
yq -r '.[0].image' | tee /dev/stderr)
[ "${actual}" = "Image1:0.0.1" ]
[ "${actual}" = "docker.io/Image1:0.0.1" ]
local actual=$(echo $object |
yq -r '.[0].imagePullPolicy' | tee /dev/stderr)
[ "${actual}" = "PullPolicy1" ]
Expand Down
2 changes: 1 addition & 1 deletion test/unit/csi-rolebinding.bats
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ load _helpers
. | tee /dev/stderr |
yq -r '.metadata.namespace' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}
}
2 changes: 1 addition & 1 deletion test/unit/injector-clusterrolebinding.bats
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ load _helpers
. | tee /dev/stderr |
yq -r '.subjects[0].namespace' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}
}
4 changes: 2 additions & 2 deletions test/unit/injector-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ load _helpers
--set 'injector.image.tag=1.2.3' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].image' | tee /dev/stderr)
[ "${actual}" = "foo:1.2.3" ]
[ "${actual}" = "docker.io/foo:1.2.3" ]

local actual=$(helm template \
--show-only templates/injector-deployment.yaml \
--set 'injector.image.repository=foo' \
--set 'injector.image.tag=1.2.3' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].image' | tee /dev/stderr)
[ "${actual}" = "foo:1.2.3" ]
[ "${actual}" = "docker.io/foo:1.2.3" ]
}

@test "injector/deployment: default imagePullPolicy" {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/injector-mutating-webhook.bats
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,4 @@ load _helpers
yq '.webhooks[0].objectSelector.matchLabels.injector' | tee /dev/stderr)

[ "${actual}" = "true" ]
}
}
2 changes: 1 addition & 1 deletion test/unit/injector-psp-role.bats
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ load _helpers
. | tee /dev/stderr |
yq -r '.metadata.namespace' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}
}
2 changes: 1 addition & 1 deletion test/unit/injector-psp-rolebinding.bats
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ load _helpers
. | tee /dev/stderr |
yq -r '.metadata.namespace' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}
}
2 changes: 1 addition & 1 deletion test/unit/server-clusterrolebinding.bats
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ load _helpers
. | tee /dev/stderr |
yq -r '.subjects[0].namespace' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}
}
4 changes: 2 additions & 2 deletions test/unit/server-dev-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ load _helpers
--set 'server.dev.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].image' | tee /dev/stderr)
[ "${actual}" = "foo:1.2.3" ]
[ "${actual}" = "quay.io/foo:1.2.3" ]
}

@test "server/ha-StatefulSet: image tag defaults to latest" {
Expand All @@ -56,7 +56,7 @@ load _helpers
--set 'server.dev.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].image' | tee /dev/stderr)
[ "${actual}" = "foo:latest" ]
[ "${actual}" = "quay.io/foo:latest" ]
}

#--------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion test/unit/server-discovery-role.bats
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ load _helpers
. | tee /dev/stderr |
yq -r '.metadata.namespace' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}
}
2 changes: 1 addition & 1 deletion test/unit/server-discovery-rolebinding.bats
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ load _helpers
. | tee /dev/stderr |
yq -r '.metadata.namespace' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}
}
28 changes: 14 additions & 14 deletions test/unit/server-ha-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ load _helpers
--set 'server.ha.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].image' | tee /dev/stderr)
[ "${actual}" = "foo:1.2.3" ]
[ "${actual}" = "quay.io/foo:1.2.3" ]
}

@test "server/ha-StatefulSet: image tag defaults to latest" {
Expand All @@ -56,7 +56,7 @@ load _helpers
--set 'server.ha.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].image' | tee /dev/stderr)
[ "${actual}" = "foo:latest" ]
[ "${actual}" = "quay.io/foo:latest" ]
}

#--------------------------------------------------------------------
Expand All @@ -71,7 +71,7 @@ load _helpers
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)

local value=$(echo $object |
yq -r 'map(select(.name=="VAULT_ADDR")) | .[] .value' | tee /dev/stderr)
yq -r 'map(select(.name=="BAO_ADDR")) | .[] .value' | tee /dev/stderr)
[ "${value}" = "http://127.0.0.1:8200" ]
}

Expand All @@ -84,7 +84,7 @@ load _helpers
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)

local value=$(echo $object |
yq -r 'map(select(.name=="VAULT_ADDR")) | .[] .value' | tee /dev/stderr)
yq -r 'map(select(.name=="BAO_ADDR")) | .[] .value' | tee /dev/stderr)
[ "${value}" = "https://127.0.0.1:8200" ]
}

Expand Down Expand Up @@ -407,7 +407,7 @@ load _helpers
}

#--------------------------------------------------------------------
# VAULT_API_ADDR renders
# BAO_API_ADDR renders

@test "server/ha-StatefulSet: api addr renders to Pod IP by default" {
cd `chart_dir`
Expand All @@ -418,7 +418,7 @@ load _helpers
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)

local value=$(echo $object |
yq -r 'map(select(.name=="VAULT_API_ADDR")) | .[] .value' | tee /dev/stderr)
yq -r 'map(select(.name=="BAO_API_ADDR")) | .[] .value' | tee /dev/stderr)
[ "${value}" = 'http://$(POD_IP):8200' ]
}

Expand All @@ -432,12 +432,12 @@ load _helpers
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)

local value=$(echo $object |
yq -r 'map(select(.name=="VAULT_API_ADDR")) | .[] .value' | tee /dev/stderr)
yq -r 'map(select(.name=="BAO_API_ADDR")) | .[] .value' | tee /dev/stderr)
[ "${value}" = "https://example.com:8200" ]
}

#--------------------------------------------------------------------
# VAULT_CLUSTER_ADDR renders
# BAO_CLUSTER_ADDR renders

@test "server/ha-StatefulSet: clusterAddr not set" {
cd `chart_dir`
Expand All @@ -449,7 +449,7 @@ load _helpers
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)

local value=$(echo $object |
yq -r 'map(select(.name=="VAULT_CLUSTER_ADDR")) | .[] .value' | tee /dev/stderr)
yq -r 'map(select(.name=="BAO_CLUSTER_ADDR")) | .[] .value' | tee /dev/stderr)
[ "${value}" = 'https://$(HOSTNAME).release-name-openbao-internal:8201' ]
}

Expand All @@ -464,7 +464,7 @@ load _helpers
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)

local value=$(echo $object |
yq -r 'map(select(.name=="VAULT_CLUSTER_ADDR")) | .[] .value' | tee /dev/stderr)
yq -r 'map(select(.name=="BAO_CLUSTER_ADDR")) | .[] .value' | tee /dev/stderr)
[ "${value}" = 'https://$(HOSTNAME).release-name-openbao-internal:8201' ]
}

Expand All @@ -479,7 +479,7 @@ load _helpers
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)

local value=$(echo $object |
yq -r 'map(select(.name=="VAULT_CLUSTER_ADDR")) | .[] .value' | tee /dev/stderr)
yq -r 'map(select(.name=="BAO_CLUSTER_ADDR")) | .[] .value' | tee /dev/stderr)
[ "${value}" = 'https://test.example.com:8201' ]
}

Expand All @@ -494,7 +494,7 @@ load _helpers
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)

local value=$(echo $object |
yq -r 'map(select(.name=="VAULT_CLUSTER_ADDR")) | .[] .value' | tee /dev/stderr)
yq -r 'map(select(.name=="BAO_CLUSTER_ADDR")) | .[] .value' | tee /dev/stderr)
[ "${value}" = 'http://$(HOSTNAME).release-name-openbao-internal:8201' ]
}

Expand All @@ -515,7 +515,7 @@ local value=$(echo $rendered |
}

#--------------------------------------------------------------------
# VAULT_RAFT_NODE_ID renders
# BAO_RAFT_NODE_ID renders

@test "server/ha-StatefulSet: raft node ID renders" {
cd `chart_dir`
Expand All @@ -528,7 +528,7 @@ local value=$(echo $rendered |
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)

local value=$(echo $object |
yq -r 'map(select(.name=="VAULT_RAFT_NODE_ID")) | .[] .valueFrom.fieldRef.fieldPath' | tee /dev/stderr)
yq -r 'map(select(.name=="BAO_RAFT_NODE_ID")) | .[] .valueFrom.fieldRef.fieldPath' | tee /dev/stderr)
[ "${value}" = "metadata.name" ]
}

Expand Down
22 changes: 0 additions & 22 deletions test/unit/server-headless-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,3 @@ load _helpers
yq '.spec.ipFamilies' -c | tee /dev/stderr)
[ "${actual}" = '["IPv4","IPv6"]' ]
}

@test "server/headless-Service: Assert ipFamilyPolicy is not set if version below 1.23" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-headless-service.yaml \
--kube-version 1.27.0 \
--set 'server.service.ipFamilyPolicy=PreferDualStack' \
. | tee /dev/stderr |
yq -r '.spec.ipFamilyPolicy' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "server/headless-Service: Assert ipFamilies is not set if version below 1.23" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-headless-service.yaml \
--kube-version 1.27.0 \
--set 'server.service.ipFamilies={IPv4,IPv6}' \
. | tee /dev/stderr |
yq -r '.spec.ipFamilies' | tee /dev/stderr)
[ "${actual}" = "null" ]
}
2 changes: 1 addition & 1 deletion test/unit/server-psp-role.bats
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ load _helpers
. | tee /dev/stderr |
yq -r '.metadata.namespace' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}
}
2 changes: 1 addition & 1 deletion test/unit/server-psp-rolebinding.bats
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ load _helpers
. | tee /dev/stderr |
yq -r '.metadata.namespace' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}
}
22 changes: 0 additions & 22 deletions test/unit/server-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -487,25 +487,3 @@ load _helpers
yq '.spec.ipFamilies' -c | tee /dev/stderr)
[ "${actual}" = '["IPv4","IPv6"]' ]
}

@test "server/Service: Assert ipFamilyPolicy is not set if version below 1.23" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-service.yaml \
--kube-version 1.27.0 \
--set 'server.service.ipFamilyPolicy=PreferDualStack' \
. | tee /dev/stderr |
yq -r '.spec.ipFamilyPolicy' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "server/Service: Assert ipFamilies is not set if version below 1.23" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-service.yaml \
--kube-version 1.27.0 \
--set 'server.service.ipFamilies={IPv4,IPv6}' \
. | tee /dev/stderr |
yq -r '.spec.ipFamilies' | tee /dev/stderr)
[ "${actual}" = "null" ]
}
2 changes: 1 addition & 1 deletion test/unit/server-serviceaccount.bats
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ load _helpers
. | tee /dev/stderr |
yq -r '.metadata.labels.foo' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}
}
Loading

0 comments on commit 5acd951

Please sign in to comment.