github.com/greenboxal/deis@v1.12.1/deisctl/backend/fleet/list_machines_test.go (about) 1 package fleet 2 3 import ( 4 "bytes" 5 "testing" 6 "text/tabwriter" 7 8 "github.com/coreos/fleet/machine" 9 ) 10 11 func TestListMachines(t *testing.T) { 12 testMachines := []machine.MachineState{ 13 machine.MachineState{ 14 ID: "123456", 15 PublicIP: "1.1.1.1", 16 Metadata: map[string]string{ 17 "foo": "bar", 18 "ping": "pong", 19 }, 20 Version: "", 21 }, 22 machine.MachineState{ 23 ID: "654321", 24 PublicIP: "2.2.2.2", 25 Metadata: nil, 26 Version: "", 27 }, 28 } 29 30 testWriter := bytes.Buffer{} 31 testTabWriter := new(tabwriter.Writer) 32 testTabWriter.Init(&testWriter, 0, 8, 1, '\t', 0) 33 34 c := &FleetClient{ 35 Fleet: &stubFleetClient{ 36 testMachineStates: testMachines, 37 }, 38 out: testTabWriter, 39 } 40 41 err := c.ListMachines() 42 43 if err != nil { 44 t.Fatal(err) 45 } 46 47 expected := `MACHINE IP METADATA 48 123456... 1.1.1.1 foo=bar,ping=pong 49 654321... 2.2.2.2 - 50 ` 51 52 actual := testWriter.String() 53 54 if expected != actual { 55 t.Errorf("Expected '%s', Got '%s'", expected, actual) 56 } 57 }