aboutsummaryrefslogtreecommitdiff
path: root/pkg/ipstack/ipstack_test.go
blob: d5b755ab9925e0239a66644ec460c15ccb9c32d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ipstack

import (
	"fmt"
	"testing"
	"time"
)

func TestInitialize(t *testing.T) {
	lnxFilePath := "../../doc-example/r2.lnx"
	err := Initialize(lnxFilePath)
	if err != nil {
		t.Error(err)
	}
	fmt.Printf("Interfaces:\n%s\n\n", SprintInterfaces())
	fmt.Printf("Neighbors:\n%s\n", SprintNeighbors())
	fmt.Printf("RoutingTable:\n%s\n", SprintRoutingTable())

	fmt.Println("TestInitialize successful")
	t.Cleanup(func() { CleanUp() })
}

func TestInterfaceUpThenDown(t *testing.T) {
	lnxFilePath := "../../doc-example/r2.lnx"
	err := Initialize(lnxFilePath)
	if err != nil {
		t.Error(err)
	}

	iface, err := GetInterfaceByName("if0")
	if err != nil {
		t.Error(err)
	}

	InterfaceUp(iface)
	if iface.State == false {
		t.Error("iface state should be true")
	}

	fmt.Printf("Interfaces:\n%s\n", SprintInterfaces())

	time.Sleep(5 * time.Millisecond) // allow time to print

	InterfaceDown(iface)
	if iface.State == true {
		t.Error("iface state should be false")
	}

	time.Sleep(5 * time.Millisecond) // allow time to print

	fmt.Printf("Interfaces:\n%s\n", SprintInterfaces())

	fmt.Println("TestInterfaceUpThenDown successful")
	t.Cleanup(func() { CleanUp() })
}