Skip to content

Commit

Permalink
Embed script using go:embed
Browse files Browse the repository at this point in the history
Signed-off-by: Dharmit Shah <[email protected]>
  • Loading branch information
dharmit committed Nov 13, 2023
1 parent be94974 commit 8ccb790
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions tests/testdata/sidecar-hook-configmap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
tempFile=$(mktemp --dry-run)
echo $4 > $tempFile
sed -i "s|<baseBoard></baseBoard>|<baseBoard><entry name='manufacturer'>Radical Edward</entry></baseBoard>|" $tempFile
cat $tempFile
10 changes: 4 additions & 6 deletions tests/vmi_hook_sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package tests_test

import (
"context"
_ "embed"
"fmt"
"time"

Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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|<baseBoard></baseBoard>|<baseBoard><entry name='manufacturer'>Radical Edward</entry></baseBoard>|" $tempFile
cat $tempFile`

return &k8sv1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "cm-",
Expand Down

0 comments on commit 8ccb790

Please sign in to comment.