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 volumeMap := elem["volume"].(VolumeConfig)
135 hostDir := volumeMap["host-dir"].(string)
136 s.volumes = append(s.volumes, hostDir)
139 s.containers = make(map[string]*Container)
140 for _, elem := range yamlTopo.Containers {
141 newContainer, err := NewContainer(elem)
143 s.T().Fatalf("config error: %v", err)
145 s.log(newContainer.getRunCommand())
146 s.containers[newContainer.name] = newContainer
150 func setupSuite(s *suite.Suite, topologyName string) func() {
152 topology, err := LoadTopology(NetworkTopologyDir, topologyName)
154 t.Fatalf("error on loading topology '%s': %v", topologyName, err)
156 err = topology.Configure()
158 t.Fatalf("failed to configure %s: %v", topologyName, err)
165 topology.Unconfigure()
169 func TestTapSuite(t *testing.T) {
174 func TestNs(t *testing.T) {
179 func TestVeths(t *testing.T) {
184 func TestNoTopo(t *testing.T) {