hs-test: manage containers and volumes within test suite

Type: test
Signed-off-by: Maros Ondrejicka <maros.ondrejicka@pantheon.tech>
Change-Id: I614111814af5a99dcaa22c8581ea2d339572ae1c
This commit is contained in:
Maros Ondrejicka
2022-12-06 19:46:24 +01:00
committed by Florin Coras
parent 5b746319d8
commit 0e79abbe2e
3 changed files with 103 additions and 117 deletions

View File

@ -13,7 +13,7 @@ import (
type HstSuite struct {
suite.Suite
teardownSuite func()
containers []string
containers []*Container
volumes []string
}
@ -56,19 +56,30 @@ func (s *HstSuite) NewContainer(name string) (*Container, error) {
return nil, fmt.Errorf("creating container failed: name must not be blank")
}
s.containers = append(s.containers, name)
container := new(Container)
container.name = name
s.containers = append(s.containers, container)
return container, nil
}
func (s *HstSuite) StopContainers() {
for _, containerName := range s.containers {
exechelper.Run("docker stop " + containerName)
for _, container := range s.containers {
container.stop()
}
}
func (s *HstSuite) NewVolume(name string) error {
err := exechelper.Run(fmt.Sprintf("docker volume create --name=%s", name))
if err != nil {
return err
}
s.volumes = append(s.volumes, name)
return nil
}
func (s *HstSuite) RemoveVolumes() {
for _, volumeName := range s.volumes {
exechelper.Run("docker volume rm " + volumeName)