package main
import (
- "fmt"
- "testing"
"io/ioutil"
+ "os"
+ "testing"
"github.com/edwarnicke/exechelper"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)
+func IsPersistent() bool {
+ return os.Getenv("HST_PERSIST") == "1"
+}
+
+func IsVerbose() bool {
+ return os.Getenv("HST_VERBOSE") == "1"
+}
+
type HstSuite struct {
suite.Suite
teardownSuite func()
}
func (s *HstSuite) TearDownTest() {
+ if IsPersistent() {
+ return
+ }
s.ResetContainers()
s.RemoveVolumes()
}
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 {
}
}
-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() {
if err != nil {
s.T().Fatalf("config error: %v", err)
}
+ s.log(newContainer.getRunCommand())
s.containers[newContainer.name] = newContainer
}
}
t.Fatalf("failed to configure %s: %v", topologyName, err)
}
- t.Logf("topo %s loaded", topologyName)
return func() {
+ if IsPersistent() {
+ return
+ }
topology.Unconfigure()
}
}