diff options
author | Maros Ondrejicka <maros.ondrejicka@pantheon.tech> | 2022-12-19 20:35:27 +0100 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2022-12-20 18:49:49 +0000 |
commit | 8753180a80e03dd031fa7f470adbcbb4a611d1c9 (patch) | |
tree | f524d7f4261b5db5861ee7e83822d99ab63f3262 /extras/hs-test/framework_test.go | |
parent | 8c626b41eaab5c74e7e023205f1c6cd655d40f44 (diff) |
hs-test: add runtime options
Options
"-p" to not remove topology elements after the test finishes
"-v" from now on extra output from tests is hidden by default,
this will show it again
Type: test
Signed-off-by: Maros Ondrejicka <maros.ondrejicka@pantheon.tech>
Change-Id: I626188561c883534e9004d5130ee2a972d12b4e2
Diffstat (limited to 'extras/hs-test/framework_test.go')
-rwxr-xr-x | extras/hs-test/framework_test.go | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/extras/hs-test/framework_test.go b/extras/hs-test/framework_test.go index a3d46ad0ab9..33bc1f35011 100755 --- a/extras/hs-test/framework_test.go +++ b/extras/hs-test/framework_test.go @@ -1,9 +1,9 @@ package main import ( - "fmt" "testing" "io/ioutil" + "os" "github.com/edwarnicke/exechelper" "github.com/stretchr/testify/assert" @@ -11,6 +11,20 @@ import ( "gopkg.in/yaml.v3" ) +func IsPersistent() bool { + if os.Getenv("HST_PERSIST") == "1" { + return true + } + return false +} + +func IsVerbose() bool { + if os.Getenv("HST_VERBOSE") == "1" { + return true + } + return false +} + type HstSuite struct { suite.Suite teardownSuite func() @@ -23,6 +37,9 @@ func (s *HstSuite) TearDownSuite() { } func (s *HstSuite) TearDownTest() { + if IsPersistent() { + return + } s.ResetContainers() s.RemoveVolumes() } @@ -30,7 +47,7 @@ func (s *HstSuite) TearDownTest() { func (s *HstSuite) SetupTest() { for _, volume := range s.volumes { cmd := "docker volume create --name=" + volume - fmt.Println(cmd) + s.log(cmd) exechelper.Run(cmd) } for _, container := range s.containers { @@ -80,20 +97,21 @@ func (s *HstSuite) assertNotContains(testString, contains interface{}, msgAndArg } } -func (s *HstSuite) ResetContainers() { - for _, container := range s.containers { - container.stop() +func (s *HstSuite) log(args ...any) { + if IsVerbose() { + s.T().Log(args...) } } -func (s *HstSuite) NewVolume(name string) error { - err := exechelper.Run(fmt.Sprintf("docker volume create --name=%s", name)) - if err != nil { - return err - } +func (s *HstSuite) skip(args ...any) { + s.log(args...) + s.T().SkipNow() +} - s.volumes = append(s.volumes, name) - return nil +func (s *HstSuite) ResetContainers() { + for _, container := range s.containers { + container.stop() + } } func (s *HstSuite) RemoveVolumes() { @@ -128,6 +146,7 @@ func (s *HstSuite) loadContainerTopology(topologyName string) { if err != nil { s.T().Fatalf("config error: %v", err) } + s.log(newContainer.getRunCommand()) s.containers[newContainer.name] = newContainer } } @@ -143,8 +162,10 @@ func setupSuite(s *suite.Suite, topologyName string) func() { t.Fatalf("failed to configure %s: %v", topologyName, err) } - t.Logf("topo %s loaded", topologyName) return func() { + if IsPersistent() { + return + } topology.Unconfigure() } } |