From d6c1b34a996e4149a1e34f3a1e6e9d0596b04d10 Mon Sep 17 00:00:00 2001 From: Ashwin Venkatesh Date: Tue, 16 Aug 2022 14:54:16 -0400 Subject: [PATCH] fix unit tests --- charts/consul/test/unit/client-daemonset.bats | 4 ++++ charts/consul/test/unit/server-statefulset.bats | 6 +++--- control-plane/connect-inject/container_init_test.go | 6 +++++- control-plane/go.mod | 2 -- control-plane/go.sum | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/charts/consul/test/unit/client-daemonset.bats b/charts/consul/test/unit/client-daemonset.bats index 32f174faab..039f513ad5 100755 --- a/charts/consul/test/unit/client-daemonset.bats +++ b/charts/consul/test/unit/client-daemonset.bats @@ -254,6 +254,7 @@ load _helpers # check that the extra-config volume is defined local volume_name=$(helm template \ -s templates/client-daemonset.yaml \ + --set 'client.enabled=true' \ . | tee /dev/stderr | yq -r '.spec.template.spec.volumes[] | select(.name == "extra-config") | .name' | tee /dev/stderr) [ "${volume_name}" = "extra-config" ] @@ -261,6 +262,7 @@ load _helpers # check that the consul container mounts the volume at /consul/extra-config local mount_path=$(helm template \ -s templates/client-daemonset.yaml \ + --set 'client.enabled=true' \ . | tee /dev/stderr | yq -r '.spec.template.spec.containers[] | select(.name == "consul") | .volumeMounts[] | select(.name == "extra-config") | .mountPath' | tee /dev/stderr) [ "${mount_path}" = "/consul/extra-config" ] @@ -987,6 +989,7 @@ load _helpers cd `chart_dir` local command=$(helm template \ -s templates/client-daemonset.yaml \ + --set 'client.enabled=true' \ --set 'global.tls.enabled=true' \ --set 'global.peering.enabled=true' \ --set 'connectInject.enabled=true' \ @@ -1008,6 +1011,7 @@ load _helpers cd `chart_dir` local command=$(helm template \ -s templates/client-daemonset.yaml \ + --set 'client.enabled=true' \ --set 'global.tls.enabled=true' \ --set 'global.peering.enabled=true' \ --set 'connectInject.enabled=true' \ diff --git a/charts/consul/test/unit/server-statefulset.bats b/charts/consul/test/unit/server-statefulset.bats index b5ed5f6c76..b0aa5b65bc 100755 --- a/charts/consul/test/unit/server-statefulset.bats +++ b/charts/consul/test/unit/server-statefulset.bats @@ -678,7 +678,7 @@ load _helpers -s templates/server-statefulset.yaml \ . | tee /dev/stderr | yq -r '.spec.template.metadata.annotations."consul.hashicorp.com/config-checksum"' | tee /dev/stderr) - [ "${actual}" = 04cc39bf3f56ff39a2f4ae188fc37fc54b7775a073e8f97111eb37a548d7e229 ] + [ "${actual}" = b13fbd9214f5131aaf1bc234c5e307db1e9be3f29a66f14a994c2a73175ab29c ] } @test "server/StatefulSet: adds config-checksum annotation when extraConfig is provided" { @@ -688,7 +688,7 @@ load _helpers --set 'server.extraConfig="{\"hello\": \"world\"}"' \ . | tee /dev/stderr | yq -r '.spec.template.metadata.annotations."consul.hashicorp.com/config-checksum"' | tee /dev/stderr) - [ "${actual}" = e8d2e9535eb6e69eedebef725a66a8b47fd8845a77772f0e19911d2273b9b804 ] + [ "${actual}" = a32421961a4d6086483ce99d496b8fc34730bc476a0245d3b7762f6d5557cef2 ] } @test "server/StatefulSet: adds config-checksum annotation when config is updated" { @@ -698,7 +698,7 @@ load _helpers --set 'global.acls.manageSystemACLs=true' \ . | tee /dev/stderr | yq -r '.spec.template.metadata.annotations."consul.hashicorp.com/config-checksum"' | tee /dev/stderr) - [ "${actual}" = d5f4de988e9d51ff8ae91a24a1a990dc65ce046c0494836f6d0f0eae34108235 ] + [ "${actual}" = a68b3056d1b756d09163f5104d13a201d1e577e7c08c2ea44163eb03b0ca98b8 ] } #-------------------------------------------------------------------- diff --git a/control-plane/connect-inject/container_init_test.go b/control-plane/connect-inject/container_init_test.go index f86525db1a..02630b63b0 100644 --- a/control-plane/connect-inject/container_init_test.go +++ b/control-plane/connect-inject/container_init_test.go @@ -216,7 +216,11 @@ consul-k8s-control-plane connect-init -pod-name=${POD_NAME} -pod-namespace=${POD h := tt.Webhook pod := *tt.Pod(minimal()) container, err := h.containerInit(testNS, pod, multiPortInfo{}) - require.NoError(t, err) + if tt.ErrStr == "" { + require.NoError(t, err) + } else { + require.Contains(t, err.Error(), tt.ErrStr) + } actual := strings.Join(container.Command, " ") require.Contains(t, actual, tt.Cmd) if tt.CmdNot != "" { diff --git a/control-plane/go.mod b/control-plane/go.mod index 1848c8f435..40e9ed30b2 100644 --- a/control-plane/go.mod +++ b/control-plane/go.mod @@ -127,6 +127,4 @@ require ( sigs.k8s.io/yaml v1.2.0 // indirect ) -replace github.com/hashicorp/consul/sdk v0.10.0 => github.com/hashicorp/consul/sdk v0.4.1-0.20220801192236-988e1fd35d51 - go 1.18 diff --git a/control-plane/go.sum b/control-plane/go.sum index 03ca166926..3c74be9132 100644 --- a/control-plane/go.sum +++ b/control-plane/go.sum @@ -299,7 +299,7 @@ github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBt github.com/hashicorp/consul/api v1.14.0 h1:Y64GIJ8hYTu+tuGekwO4G4ardXoiCivX9wv1iP/kihk= github.com/hashicorp/consul/api v1.14.0/go.mod h1:bcaw5CSZ7NE9qfOfKCI1xb7ZKjzu/MyvQkCLTfqLqxQ= github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= -github.com/hashicorp/consul/sdk v0.4.1-0.20220801192236-988e1fd35d51/go.mod h1:yPkX5Q6CsxTFMjQQDJwzeNmUUF5NUGGbrDsv9wTb8cw= +github.com/hashicorp/consul/sdk v0.10.0/go.mod h1:yPkX5Q6CsxTFMjQQDJwzeNmUUF5NUGGbrDsv9wTb8cw= github.com/hashicorp/consul/sdk v0.11.0 h1:HRzj8YSCln2yGgCumN5CL8lYlD3gBurnervJRJAZyC4= github.com/hashicorp/consul/sdk v0.11.0/go.mod h1:yPkX5Q6CsxTFMjQQDJwzeNmUUF5NUGGbrDsv9wTb8cw= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=