From 67b5e3155864d695fccdf1e365aa97e7f1221055 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Tue, 30 Dec 2014 13:11:59 -0500 Subject: [PATCH 1/2] fleetctl: testing of mapTargetField --- fleetctl/list_unit_files_test.go | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/fleetctl/list_unit_files_test.go b/fleetctl/list_unit_files_test.go index 0ffbe2ad0..6814606f8 100644 --- a/fleetctl/list_unit_files_test.go +++ b/fleetctl/list_unit_files_test.go @@ -83,3 +83,45 @@ func TestListUnitFilesFieldsToStrings(t *testing.T) { assertEqual(t, "hash", uh, fuh) assertEqual(t, "hash", uh[:7], suh) } + +func TestMapTargetField(t *testing.T) { + // seeding the cache for the following test cases + machineStates = map[string]*machine.MachineState{ + "XXX": &machine.MachineState{ID: "XXX"}, + } + + tests := []struct { + unit schema.Unit + want string + }{ + // already scheduled + { + unit: schema.Unit{ + MachineID: "XXX", + }, + want: "XXX", + }, + // not yet scheduled + { + unit: schema.Unit{}, + want: "-", + }, + // global unit + { + unit: schema.Unit{ + Options: []*schema.UnitOption{ + &schema.UnitOption{Section: "X-Fleet", Name: "Global", Value: "true"}, + }, + }, + want: "-", + }, + } + + for i, tt := range tests { + // eliminate the "full" variable from test cases by hard-coding "true" below + got := mapTargetField(tt.unit, true) + if tt.want != got { + t.Errorf("case %d: want=%q got=%q", i, tt.want, got) + } + } +} From fa087b6f6b987e2388f6fdbd6eee6f0c6b5c0d0b Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Tue, 30 Dec 2014 13:14:55 -0500 Subject: [PATCH 2/2] fleetctl: fill global unit TARGET in list-unit-files --- fleetctl/list_unit_files.go | 5 ++++- fleetctl/list_unit_files_test.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fleetctl/list_unit_files.go b/fleetctl/list_unit_files.go index bd1ea5efe..af78a4464 100644 --- a/fleetctl/list_unit_files.go +++ b/fleetctl/list_unit_files.go @@ -31,7 +31,10 @@ const ( ) func mapTargetField(u schema.Unit, full bool) string { - if suToGlobal(u) || u.MachineID == "" { + if suToGlobal(u) { + return "global" + } + if u.MachineID == "" { return "-" } ms := cachedMachineState(u.MachineID) diff --git a/fleetctl/list_unit_files_test.go b/fleetctl/list_unit_files_test.go index 6814606f8..9cded4976 100644 --- a/fleetctl/list_unit_files_test.go +++ b/fleetctl/list_unit_files_test.go @@ -113,7 +113,7 @@ func TestMapTargetField(t *testing.T) { &schema.UnitOption{Section: "X-Fleet", Name: "Global", Value: "true"}, }, }, - want: "-", + want: "global", }, }