-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
53 lines (44 loc) · 1.38 KB
/
main_test.go
File metadata and controls
53 lines (44 loc) · 1.38 KB
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
package main
import (
"net"
"os"
"os/user"
"path"
"testing"
)
// This test also tests getConfigDir
func TestGetTemplateDir(t *testing.T) {
// Test without XDG_CONFIG_DIR set
os.Unsetenv("XDG_CONFIG_HOME")
user, _ := user.Current()
expectedDir := path.Join(user.HomeDir, ".config", "lab-cli", "templates")
templateDir, _ := getTemplateDir()
if templateDir != expectedDir {
t.Errorf("did not get the template directoy we wanted. got: %s, want: %s", templateDir, expectedDir)
}
// With XDG_CONFIG_DIR set
os.Setenv("XDG_CONFIG_HOME", path.Join("/tmp", ".config"))
expectedDir = path.Join("/tmp", ".config", "lab-cli", "templates")
templateDir, _ = getTemplateDir()
if templateDir != expectedDir {
t.Errorf("did not get the template directoy we wanted. got: %s, want: %s", templateDir, expectedDir)
}
}
func TestNextAddress(t *testing.T) {
var tests = []struct {
ip net.IP
want net.IP
}{
{net.ParseIP("127.0.0.1"), net.ParseIP("127.0.0.2")},
{net.ParseIP("192.168.100.50"), net.ParseIP("192.168.100.51")},
{net.ParseIP("255.255.255.255"), net.ParseIP("0.0.0.0")},
{net.ParseIP("::1"), nil}, // Invalid IPv4 address
{net.ParseIP("blablab"), nil}, // Invalid IPv4 address
}
for _, test := range tests {
nextAddr := nextAddress(test.ip)
if !nextAddr.Equal(test.want) {
t.Errorf("invalid next IP address. got: %s, want: %s", nextAddr, test.want)
}
}
}