-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhost_test.go
38 lines (32 loc) · 1.09 KB
/
host_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
package main
import (
"reflect"
"testing"
"github.com/tactycal/agent/stubUtils"
)
func TestGetHostInfo(t *testing.T) {
s := stubUtils.NewStubs(t,
&stubUtils.ReadFileStub{Path: "/etc/os-release", Output: []byte("ID=ubuntu\nID_LIKE=debian\nVERSION_ID=\"14.04\"")},
&stubUtils.CmdStub{Cmd: "uname", Args: []string{"-m"}, Output: []byte("ARCH")},
&stubUtils.CmdStub{Cmd: "uname", Args: []string{"-r"}, Output: []byte("KERN")},
&stubUtils.CmdStub{Cmd: "hostname", Args: []string{"-f"}, Output: []byte("FQDN")},
)
defer s.Close()
expected := &Host{
Fqdn: "FQDN",
Distribution: "ubuntu",
Release: "14.04",
Architecture: "ARCH",
Kernel: "KERN",
}
host, _ := GetHostInfo()
if !reflect.DeepEqual(host, expected) {
t.Errorf("Host\n%+v\ndoesn't match expected\n%+v\n", host, expected)
}
s.Add(&stubUtils.ReadFileStub{Path: "/etc/os-release", Output: []byte("ID=ubuntu\nID_LIKE=debian\nVERSION_ID=\"14.04\"")},
&stubUtils.CmdStub{Cmd: "uname", Args: []string{"-m"}, Err: stubUtils.OhNoErr})
_, err := GetHostInfo()
if err == nil {
t.Error("An error was expected")
}
}