summaryrefslogtreecommitdiffstats
path: root/extras/hs-test/container.go
diff options
context:
space:
mode:
authorMaros Ondrejicka <maros.ondrejicka@pantheon.tech>2022-12-06 19:46:24 +0100
committerFlorin Coras <florin.coras@gmail.com>2022-12-06 20:06:35 +0000
commit0e79abbe2e4183fe32400bdfcbe0465a8f536ea1 (patch)
tree3ee302f5c4d645e9473a2d537f89ca3882aedc51 /extras/hs-test/container.go
parent5b746319d84854f942a48f0fb48a0f02af57f420 (diff)
hs-test: manage containers and volumes within test suite
Type: test Signed-off-by: Maros Ondrejicka <maros.ondrejicka@pantheon.tech> Change-Id: I614111814af5a99dcaa22c8581ea2d339572ae1c
Diffstat (limited to 'extras/hs-test/container.go')
-rw-r--r--extras/hs-test/container.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/extras/hs-test/container.go b/extras/hs-test/container.go
index 3128a8ecdd5..e9aa7b261c4 100644
--- a/extras/hs-test/container.go
+++ b/extras/hs-test/container.go
@@ -6,8 +6,14 @@ import (
"github.com/edwarnicke/exechelper"
)
-type Container struct {
+type Volume struct {
name string
+ path string
+}
+
+type Container struct {
+ name string
+ volumes []*Volume
}
func (c *Container) run() error {
@@ -19,6 +25,7 @@ func (c *Container) run() error {
syncPath := fmt.Sprintf("-v /tmp/%s/sync:/tmp/sync", c.name)
cmd := "docker run --cap-add=all -d --privileged --network host --rm "
cmd += syncPath
+ cmd += c.getVolumes()
cmd += " --name " + c.name + " hs-test/vpp"
fmt.Println(cmd)
err := exechelper.Run(cmd)
@@ -29,3 +36,22 @@ func (c *Container) run() error {
return nil
}
+func (c *Container) addVolume(name string, containerPath string) {
+ c.volumes = append(c.volumes, &Volume{name, containerPath})
+}
+
+func (c *Container) getVolumes() string {
+ dockerOption := ""
+
+ if len(c.volumes) > 0 {
+ for _, volume := range c.volumes {
+ dockerOption += fmt.Sprintf(" -v %s:%s", volume.name, volume.path)
+ }
+ }
+
+ return dockerOption
+}
+
+func (c *Container) stop() error {
+ return exechelper.Run("docker stop " + c.name)
+}