hs-test: remove exec flags from source files
[vpp.git] / extras / hs-test / framework_test.go
old mode 100755 (executable)
new mode 100644 (file)
index a3d46ad..056be13
@@ -1,9 +1,9 @@
 package main
 
 import (
-       "fmt"
-       "testing"
        "io/ioutil"
+       "os"
+       "testing"
 
        "github.com/edwarnicke/exechelper"
        "github.com/stretchr/testify/assert"
@@ -11,6 +11,14 @@ import (
        "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()
@@ -23,6 +31,9 @@ func (s *HstSuite) TearDownSuite() {
 }
 
 func (s *HstSuite) TearDownTest() {
+       if IsPersistent() {
+               return
+       }
        s.ResetContainers()
        s.RemoveVolumes()
 }
@@ -30,7 +41,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 +91,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 +140,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 +156,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()
        }
 }
@@ -163,3 +178,8 @@ func TestVeths(t *testing.T) {
        var m VethsSuite
        suite.Run(t, &m)
 }
+
+func TestNoTopo(t *testing.T) {
+       var m NoTopoSuite
+       suite.Run(t, &m)
+}