misc: add test framework for host stack
[vpp.git] / extras / hs-test / framework_test.go
1 package main
2
3 import (
4         "testing"
5         "time"
6
7         "github.com/stretchr/testify/suite"
8 )
9
10 type TapSuite struct {
11         suite.Suite
12         teardownSuite func()
13 }
14
15 func (s *TapSuite) SetupSuite() {
16         time.Sleep(1 * time.Second)
17         s.teardownSuite = setupSuite(&s.Suite, "tap")
18 }
19
20 func (s *TapSuite) TearDownSuite() {
21         s.teardownSuite()
22 }
23
24 type Veths2Suite struct {
25         suite.Suite
26         teardownSuite func()
27 }
28
29 func (s *Veths2Suite) SetupSuite() {
30         time.Sleep(1 * time.Second)
31         s.teardownSuite = setupSuite(&s.Suite, "2peerVeth")
32 }
33
34 func (s *Veths2Suite) TearDownSuite() {
35         s.teardownSuite()
36 }
37
38 type NsSuite struct {
39         suite.Suite
40         teardownSuite func()
41 }
42
43 func (s *NsSuite) SetupSuite() {
44         s.teardownSuite = setupSuite(&s.Suite, "ns")
45 }
46
47 func (s *NsSuite) TearDownSuite() {
48         s.teardownSuite()
49 }
50
51 func setupSuite(s *suite.Suite, topologyName string) func() {
52         t := s.T()
53         topology, err := LoadTopology(TopologyDir, topologyName)
54         if err != nil {
55                 t.Fatalf("error on loading topology '%s': %v", topologyName, err)
56         }
57         err = topology.Configure()
58         if err != nil {
59                 t.Fatalf("failed to configure %s: %v", topologyName, err)
60         }
61
62         t.Logf("topo %s loaded", topologyName)
63         return func() {
64                 topology.Unconfigure()
65         }
66 }
67
68 func TestTapSuite(t *testing.T) {
69         var m TapSuite
70         suite.Run(t, &m)
71 }
72
73 func TestNs(t *testing.T) {
74         var m NsSuite
75         suite.Run(t, &m)
76 }
77
78 func TestVeths2(t *testing.T) {
79         var m Veths2Suite
80         suite.Run(t, &m)
81
82 }