aboutsummaryrefslogtreecommitdiffstats
path: root/extras/hs-test/container.go
diff options
context:
space:
mode:
authorMaros Ondrejicka <mondreji@cisco.com>2023-02-28 12:49:43 +0100
committerFlorin Coras <florin.coras@gmail.com>2023-02-28 22:13:21 +0000
commit85396a5488264690c7da2684742e4a5f38d192a7 (patch)
treed9afdf5bb8a7fd965adb2c3d4aa4111b7abb02d7 /extras/hs-test/container.go
parent729b9c94f8222346a61c21d21a674bcb9b5974f8 (diff)
hs-test: fill configuration files at runtime
Treat certain configuration files, which contain runtime-dependent information, as templates. The information is filled at runtime and the files are copied into containers. This allows to avoid hard-coding IP addresses into configuration files. Type: test Signed-off-by: Maros Ondrejicka <mondreji@cisco.com> Change-Id: I1dae8f15f4f76c0bf1779d7c68b7f3859bf5a861
Diffstat (limited to 'extras/hs-test/container.go')
-rw-r--r--extras/hs-test/container.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/extras/hs-test/container.go b/extras/hs-test/container.go
index 5def2789528..40dc0828376 100644
--- a/extras/hs-test/container.go
+++ b/extras/hs-test/container.go
@@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"strings"
+ "text/template"
"github.com/edwarnicke/exechelper"
)
@@ -301,3 +302,19 @@ func (c *Container) stop() error {
c.saveLogs()
return exechelper.Run("docker stop " + c.name + " -t 0")
}
+
+func (c *Container) createConfig(targetConfigName string, templateName string, values any) {
+ template := template.Must(template.ParseFiles(templateName))
+
+ f, err := os.CreateTemp("/tmp/hs-test/", "hst-config")
+ c.Suite().assertNil(err)
+ defer os.Remove(f.Name())
+
+ err = template.Execute(f, values)
+ c.Suite().assertNil(err)
+
+ err = f.Close()
+ c.Suite().assertNil(err)
+
+ c.copy(f.Name(), targetConfigName)
+}