From 8ccb790fee72a3fa35545668dad169d0dda898ac Mon Sep 17 00:00:00 2001 From: Dharmit Shah Date: Mon, 30 Oct 2023 17:58:47 +0530 Subject: [PATCH] Embed script using go:embed Signed-off-by: Dharmit Shah --- tests/BUILD.bazel | 2 ++ tests/testdata/sidecar-hook-configmap.sh | 5 +++++ tests/vmi_hook_sidecar_test.go | 10 ++++------ 3 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 tests/testdata/sidecar-hook-configmap.sh diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel index f77c87658af3..cf04c74ba03d 100644 --- a/tests/BUILD.bazel +++ b/tests/BUILD.bazel @@ -150,7 +150,9 @@ go_test( "vnc_test.go", "windows_test.go", ], + data = glob(["testdata/**"]), embed = [":go_default_library"], + embedsrcs = ["testdata/sidecar-hook-configmap.sh"], visibility = ["//visibility:public"], deps = [ "//pkg/apimachinery/patch:go_default_library", diff --git a/tests/testdata/sidecar-hook-configmap.sh b/tests/testdata/sidecar-hook-configmap.sh new file mode 100644 index 000000000000..28db7c2b42e5 --- /dev/null +++ b/tests/testdata/sidecar-hook-configmap.sh @@ -0,0 +1,5 @@ +#!/bin/sh +tempFile=$(mktemp --dry-run) +echo $4 > $tempFile +sed -i "s||Radical Edward|" $tempFile +cat $tempFile \ No newline at end of file diff --git a/tests/vmi_hook_sidecar_test.go b/tests/vmi_hook_sidecar_test.go index 8e56523c9398..9597c0e61309 100644 --- a/tests/vmi_hook_sidecar_test.go +++ b/tests/vmi_hook_sidecar_test.go @@ -21,6 +21,7 @@ package tests_test import ( "context" + _ "embed" "fmt" "time" @@ -56,6 +57,9 @@ const ( configMapKey = "my_script" ) +//go:embed testdata/sidecar-hook-configmap.sh +var configMapData string + var _ = Describe("[sig-compute]HookSidecars", decorators.SigCompute, func() { var ( @@ -283,12 +287,6 @@ func RenderSidecarWithConfigMap(version, name string) map[string]string { } func RenderConfigMap() *k8sv1.ConfigMap { - var configMapData = `#!/bin/sh -tempFile=$(mktemp --dry-run) -echo $4 > $tempFile -sed -i "s||Radical Edward|" $tempFile -cat $tempFile` - return &k8sv1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ GenerateName: "cm-",