8 "github.com/edwarnicke/exechelper"
9 "github.com/stretchr/testify/assert"
10 "github.com/stretchr/testify/suite"
14 type HstSuite struct {
17 containers map[string]*Container
21 func (s *HstSuite) TearDownSuite() {
25 func (s *HstSuite) TearDownTest() {
30 func (s *HstSuite) SetupTest() {
31 for _, volume := range s.volumes {
32 cmd := "docker volume create --name=" + volume
36 for _, container := range s.containers {
37 if container.isOptional == false {
43 func (s *HstSuite) hstFail() {
47 func (s *HstSuite) assertNil(object interface{}, msgAndArgs ...interface{}) {
48 if !assert.Nil(s.T(), object, msgAndArgs...) {
53 func (s *HstSuite) assertNotNil(object interface{}, msgAndArgs ...interface{}) {
54 if !assert.NotNil(s.T(), object, msgAndArgs...) {
59 func (s *HstSuite) assertEqual(expected, actual interface{}, msgAndArgs ...interface{}) {
60 if !assert.Equal(s.T(), expected, actual, msgAndArgs...) {
65 func (s *HstSuite) assertNotEqual(expected, actual interface{}, msgAndArgs ...interface{}) {
66 if !assert.NotEqual(s.T(), expected, actual, msgAndArgs...) {
71 func (s *HstSuite) assertContains(testString, contains interface{}, msgAndArgs ...interface{}) {
72 if !assert.Contains(s.T(), testString, contains, msgAndArgs...) {
77 func (s *HstSuite) assertNotContains(testString, contains interface{}, msgAndArgs ...interface{}) {
78 if !assert.NotContains(s.T(), testString, contains, msgAndArgs...) {
83 func (s *HstSuite) ResetContainers() {
84 for _, container := range s.containers {
89 func (s *HstSuite) NewVolume(name string) error {
90 err := exechelper.Run(fmt.Sprintf("docker volume create --name=%s", name))
95 s.volumes = append(s.volumes, name)
99 func (s *HstSuite) RemoveVolumes() {
100 for _, volumeName := range s.volumes {
101 cmd := "docker volume rm " + volumeName
106 func (s *HstSuite) getContainerByName(name string) *Container {
107 return s.containers[name]
110 func (s *HstSuite) loadContainerTopology(topologyName string) {
111 data, err := ioutil.ReadFile(ContainerTopologyDir + topologyName + ".yaml")
113 s.T().Fatalf("read error: %v", err)
115 var yamlTopo YamlTopology
116 err = yaml.Unmarshal(data, &yamlTopo)
118 s.T().Fatalf("unmarshal error: %v", err)
121 for _, elem := range yamlTopo.Volumes {
122 s.volumes = append(s.volumes, elem)
125 s.containers = make(map[string]*Container)
126 for _, elem := range yamlTopo.Containers {
127 newContainer, err := NewContainer(elem)
129 s.T().Fatalf("config error: %v", err)
131 s.containers[newContainer.name] = newContainer
135 func setupSuite(s *suite.Suite, topologyName string) func() {
137 topology, err := LoadTopology(NetworkTopologyDir, topologyName)
139 t.Fatalf("error on loading topology '%s': %v", topologyName, err)
141 err = topology.Configure()
143 t.Fatalf("failed to configure %s: %v", topologyName, err)
146 t.Logf("topo %s loaded", topologyName)
148 topology.Unconfigure()
152 func TestTapSuite(t *testing.T) {
157 func TestNs(t *testing.T) {
162 func TestVeths(t *testing.T) {