blob: 78a289265be099b892b3bc127a20d6a9d54b0bed [file] [log] [blame]
Filip Tehlar229f5fc2022-08-09 14:44:47 +00001package main
2
3import (
4 "testing"
5 "time"
6
7 "github.com/stretchr/testify/suite"
8)
9
10type TapSuite struct {
11 suite.Suite
12 teardownSuite func()
13}
14
15func (s *TapSuite) SetupSuite() {
16 time.Sleep(1 * time.Second)
17 s.teardownSuite = setupSuite(&s.Suite, "tap")
18}
19
20func (s *TapSuite) TearDownSuite() {
21 s.teardownSuite()
22}
23
24type Veths2Suite struct {
25 suite.Suite
26 teardownSuite func()
27}
28
29func (s *Veths2Suite) SetupSuite() {
30 time.Sleep(1 * time.Second)
31 s.teardownSuite = setupSuite(&s.Suite, "2peerVeth")
32}
33
34func (s *Veths2Suite) TearDownSuite() {
35 s.teardownSuite()
36}
37
38type NsSuite struct {
39 suite.Suite
40 teardownSuite func()
41}
42
43func (s *NsSuite) SetupSuite() {
44 s.teardownSuite = setupSuite(&s.Suite, "ns")
45}
46
47func (s *NsSuite) TearDownSuite() {
48 s.teardownSuite()
49}
50
51func 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
68func TestTapSuite(t *testing.T) {
69 var m TapSuite
70 suite.Run(t, &m)
71}
72
73func TestNs(t *testing.T) {
74 var m NsSuite
75 suite.Run(t, &m)
76}
77
78func TestVeths2(t *testing.T) {
79 var m Veths2Suite
80 suite.Run(t, &m)
81
82}