-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaboutme_test.go
More file actions
59 lines (48 loc) · 1.2 KB
/
aboutme_test.go
File metadata and controls
59 lines (48 loc) · 1.2 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
54
55
56
57
58
59
package aboutme
import (
"net"
"os"
"testing"
"k8s.io/kubernetes/pkg/client/unversioned"
)
func TestFromEnv(t *testing.T) {
if _, err := unversioned.InClusterConfig(); err != nil {
t.Skip("This can only be run inside Kubernetes. Skipping.")
}
me, err := FromEnv()
if err != nil {
t.Errorf("Could not get an environment: %s", err)
}
if len(me.Name) == 0 {
t.Error("Could not get a pod name.")
}
}
func TestShuntEnv(t *testing.T) {
e := &Me{
Annotations: map[string]string{"a": "a"},
Labels: map[string]string{"b": "b"},
Name: "c",
}
e.ShuntEnv()
if "a" != os.Getenv("MY_ANNOTATION_A") {
t.Errorf("Expected 'a', got '%s'", os.Getenv("MY_ANNOTATION_A"))
}
if "b" != os.Getenv("MY_LABEL_B") {
t.Errorf("Expected 'b', got '%s'", os.Getenv("MY_LABEL_B"))
}
if "c" != os.Getenv("MY_NAME") {
t.Errorf("Expected 'c', got '%s'", os.Getenv("MY_NAME"))
}
}
func TestMyIP(t *testing.T) {
if _, err := net.InterfaceByName("eth0"); err != nil {
t.Skip("Host operating system does not have an eth0 device to test.")
}
ip, err := MyIP()
if err != nil {
t.Errorf("Could not get IP address: %s", err)
}
if len(ip) == 0 {
t.Errorf("Expected a valid IP address. Got nuthin.")
}
}