-
Notifications
You must be signed in to change notification settings - Fork 10
/
alias_test.go
65 lines (61 loc) · 1.48 KB
/
alias_test.go
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
56
57
58
59
60
61
62
63
64
65
package main
import (
"testing"
)
func TestNewAlias(t *testing.T) {
tests := []struct {
name string
file string
err bool
count int
m map[string]string
}{
{
name: "invalid-file",
file: "no-such-file.txt",
err: true,
},
{
name: "valid-file-syntax error",
file: "tests/data/juniper-junos/alias/alias-error.txt",
err: true,
},
{
name: "valid-file",
file: "tests/data/juniper-junos/alias/alias.txt",
err: false,
count: 10,
m: map[string]string{
"no-does-not-exists-in-test-data": "no-does-not-exists-in-test-data",
"/interfaces/interface/subinterfaces/subinterface/state/counters/in-unicast-pkts": "ifl-in-ucast-pkts",
"/interfaces/interface/@name": "physical_interface",
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
alias, err := NewAlias(test.file)
if test.err && err == nil {
t.Errorf("want error, got nil")
}
if !test.err && err != nil {
t.Errorf("%v", err)
}
if !test.err {
if test.count != len(alias.m) {
t.Errorf("count: want %d, got %d", test.count, len(alias.m))
}
for k, v := range test.m {
r := getAlias(alias, k)
if r != v {
t.Errorf("want %s, got %s", v, r)
}
}
r := getAlias(nil, "empty-alias")
if r != "empty-alias" {
t.Errorf("nil-alias failed: want empty-alias, got %s", r)
}
}
})
}
}