github.com/fanux/shipyard@v0.0.0-20161009071005-6515ce223235/controller/manager/utils_test.go (about) 1 package manager 2 3 import ( 4 "testing" 5 ) 6 7 func TestParseDriverStatus(t *testing.T) { 8 driverStatus := [][]string{ 9 []string{"\u0008Strategy", "spread"}, 10 []string{"\u0008Filters", "affinity, health, constraint"}, 11 []string{"\u0008Nodes", "1"}, 12 []string{"localhost", "127.0.0.1:2375"}, 13 []string{" └ Containers", "10"}, 14 []string{" └ Reserved CPUs", "1 / 4"}, 15 []string{" └ Reserved Memory", "2 / 8.083GiB"}, 16 []string{" └ Labels", "executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), storagedriver=btrfs"}, 17 []string{"remote", "1.2.3.4:2375"}, 18 []string{" └ Containers", "3"}, 19 []string{" └ Reserved CPUs", "0 / 4"}, 20 []string{" └ Reserved Memory", "0 / 8.083GiB"}, 21 []string{" └ Labels", "executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), storagedriver=aufs"}, 22 } 23 24 nodes, err := parseClusterNodes(driverStatus) 25 if err != nil { 26 t.Fatal(err) 27 } 28 29 if len(nodes) != 2 { 30 t.Fatalf("expected 2 nodes; received %d", len(nodes)) 31 } 32 33 n1 := nodes[0] 34 n2 := nodes[1] 35 36 if n1.Name != "localhost" { 37 t.Fatalf("expected name 'localhost'; received %q", n1.Name) 38 } 39 40 if n1.Addr != "127.0.0.1:2375" { 41 t.Fatalf("expected addr '127.0.0.1:2375'; received %q", n1.Addr) 42 } 43 44 if n1.Containers != "10" { 45 t.Fatalf("expected 10 containers; received %q", n1.Containers) 46 } 47 48 if n1.ReservedCPUs != "1 / 4" { 49 t.Fatalf("expected 1 / 4 cpus; received %q", n1.ReservedCPUs) 50 } 51 52 if n2.Name != "remote" { 53 t.Fatalf("expected name 'remote'; received %q", n2.Name) 54 } 55 56 if n2.Addr != "1.2.3.4:2375" { 57 t.Fatalf("expected addr '1.2.3.4:2375'; received %q", n2.Addr) 58 } 59 60 if n2.Containers != "3" { 61 t.Fatalf("expected 3 containers; received %q", n1.Containers) 62 } 63 64 if n2.ReservedCPUs != "0 / 4" { 65 t.Fatalf("expected 0 / 4 cpus; received %q", n2.ReservedCPUs) 66 } 67 68 }