8 "github.com/edwarnicke/exechelper"
9 "github.com/stretchr/testify/assert"
10 "github.com/stretchr/testify/suite"
14 func IsPersistent() bool {
15 if os.Getenv("HST_PERSIST") == "1" {
21 func IsVerbose() bool {
22 if os.Getenv("HST_VERBOSE") == "1" {
28 type HstSuite struct {
31 containers map[string]*Container
35 func (s *HstSuite) TearDownSuite() {
39 func (s *HstSuite) TearDownTest() {
47 func (s *HstSuite) SetupTest() {
48 for _, volume := range s.volumes {
49 cmd := "docker volume create --name=" + volume
53 for _, container := range s.containers {
54 if container.isOptional == false {
60 func (s *HstSuite) hstFail() {
64 func (s *HstSuite) assertNil(object interface{}, msgAndArgs ...interface{}) {
65 if !assert.Nil(s.T(), object, msgAndArgs...) {
70 func (s *HstSuite) assertNotNil(object interface{}, msgAndArgs ...interface{}) {
71 if !assert.NotNil(s.T(), object, msgAndArgs...) {
76 func (s *HstSuite) assertEqual(expected, actual interface{}, msgAndArgs ...interface{}) {
77 if !assert.Equal(s.T(), expected, actual, msgAndArgs...) {
82 func (s *HstSuite) assertNotEqual(expected, actual interface{}, msgAndArgs ...interface{}) {
83 if !assert.NotEqual(s.T(), expected, actual, msgAndArgs...) {
88 func (s *HstSuite) assertContains(testString, contains interface{}, msgAndArgs ...interface{}) {
89 if !assert.Contains(s.T(), testString, contains, msgAndArgs...) {
94 func (s *HstSuite) assertNotContains(testString, contains interface{}, msgAndArgs ...interface{}) {
95 if !assert.NotContains(s.T(), testString, contains, msgAndArgs...) {
100 func (s *HstSuite) log(args ...any) {
106 func (s *HstSuite) skip(args ...any) {
111 func (s *HstSuite) ResetContainers() {
112 for _, container := range s.containers {
117 func (s *HstSuite) RemoveVolumes() {
118 for _, volumeName := range s.volumes {
119 cmd := "docker volume rm " + volumeName
124 func (s *HstSuite) getContainerByName(name string) *Container {
125 return s.containers[name]
128 func (s *HstSuite) loadContainerTopology(topologyName string) {
129 data, err := ioutil.ReadFile(ContainerTopologyDir + topologyName + ".yaml")
131 s.T().Fatalf("read error: %v", err)
133 var yamlTopo YamlTopology
134 err = yaml.Unmarshal(data, &yamlTopo)
136 s.T().Fatalf("unmarshal error: %v", err)
139 for _, elem := range yamlTopo.Volumes {
140 s.volumes = append(s.volumes, elem)
143 s.containers = make(map[string]*Container)
144 for _, elem := range yamlTopo.Containers {
145 newContainer, err := NewContainer(elem)
147 s.T().Fatalf("config error: %v", err)
149 s.log(newContainer.getRunCommand())
150 s.containers[newContainer.name] = newContainer
154 func setupSuite(s *suite.Suite, topologyName string) func() {
156 topology, err := LoadTopology(NetworkTopologyDir, topologyName)
158 t.Fatalf("error on loading topology '%s': %v", topologyName, err)
160 err = topology.Configure()
162 t.Fatalf("failed to configure %s: %v", topologyName, err)
169 topology.Unconfigure()
173 func TestTapSuite(t *testing.T) {
178 func TestNs(t *testing.T) {
183 func TestVeths(t *testing.T) {