8 "github.com/edwarnicke/exechelper"
9 "github.com/stretchr/testify/assert"
10 "github.com/stretchr/testify/suite"
14 func IsPersistent() bool {
15 return os.Getenv("HST_PERSIST") == "1"
18 func IsVerbose() bool {
19 return os.Getenv("HST_VERBOSE") == "1"
22 type HstSuite struct {
25 containers map[string]*Container
29 func (s *HstSuite) TearDownSuite() {
33 func (s *HstSuite) TearDownTest() {
41 func (s *HstSuite) SetupTest() {
42 for _, volume := range s.volumes {
43 cmd := "docker volume create --name=" + volume
47 for _, container := range s.containers {
48 if container.isOptional == false {
54 func (s *HstSuite) hstFail() {
58 func (s *HstSuite) assertNil(object interface{}, msgAndArgs ...interface{}) {
59 if !assert.Nil(s.T(), object, msgAndArgs...) {
64 func (s *HstSuite) assertNotNil(object interface{}, msgAndArgs ...interface{}) {
65 if !assert.NotNil(s.T(), object, msgAndArgs...) {
70 func (s *HstSuite) assertEqual(expected, actual interface{}, msgAndArgs ...interface{}) {
71 if !assert.Equal(s.T(), expected, actual, msgAndArgs...) {
76 func (s *HstSuite) assertNotEqual(expected, actual interface{}, msgAndArgs ...interface{}) {
77 if !assert.NotEqual(s.T(), expected, actual, msgAndArgs...) {
82 func (s *HstSuite) assertContains(testString, contains interface{}, msgAndArgs ...interface{}) {
83 if !assert.Contains(s.T(), testString, contains, msgAndArgs...) {
88 func (s *HstSuite) assertNotContains(testString, contains interface{}, msgAndArgs ...interface{}) {
89 if !assert.NotContains(s.T(), testString, contains, msgAndArgs...) {
94 func (s *HstSuite) log(args ...any) {
100 func (s *HstSuite) skip(args ...any) {
105 func (s *HstSuite) ResetContainers() {
106 for _, container := range s.containers {
111 func (s *HstSuite) RemoveVolumes() {
112 for _, volumeName := range s.volumes {
113 cmd := "docker volume rm " + volumeName
118 func (s *HstSuite) getContainerByName(name string) *Container {
119 return s.containers[name]
122 func (s *HstSuite) loadContainerTopology(topologyName string) {
123 data, err := ioutil.ReadFile(ContainerTopologyDir + topologyName + ".yaml")
125 s.T().Fatalf("read error: %v", err)
127 var yamlTopo YamlTopology
128 err = yaml.Unmarshal(data, &yamlTopo)
130 s.T().Fatalf("unmarshal error: %v", err)
133 for _, elem := range yamlTopo.Volumes {
134 s.volumes = append(s.volumes, elem)
137 s.containers = make(map[string]*Container)
138 for _, elem := range yamlTopo.Containers {
139 newContainer, err := NewContainer(elem)
141 s.T().Fatalf("config error: %v", err)
143 s.log(newContainer.getRunCommand())
144 s.containers[newContainer.name] = newContainer
148 func setupSuite(s *suite.Suite, topologyName string) func() {
150 topology, err := LoadTopology(NetworkTopologyDir, topologyName)
152 t.Fatalf("error on loading topology '%s': %v", topologyName, err)
154 err = topology.Configure()
156 t.Fatalf("failed to configure %s: %v", topologyName, err)
163 topology.Unconfigure()
167 func TestTapSuite(t *testing.T) {
172 func TestNs(t *testing.T) {
177 func TestVeths(t *testing.T) {