From ab558997ed308bb78015d3cfb9b7a2a7b41df947 Mon Sep 17 00:00:00 2001 From: Jonathan McCall Date: Fri, 16 Sep 2016 17:25:06 -0400 Subject: [PATCH] Fix tests broken by #46 --- cli.go | 10 +++++----- parser_test.go | 10 +++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cli.go b/cli.go index 23344d6..4510a94 100644 --- a/cli.go +++ b/cli.go @@ -8,8 +8,8 @@ import ( ) type allGroup struct { - Hosts []string `json:"hosts"` - Vars map[string]string `json:"vars"` + Hosts []string `json:"hosts"` + Vars map[string]interface{} `json:"vars"` } func appendUniq(strs []string, item string) []string { @@ -27,7 +27,7 @@ func appendUniq(strs []string, item string) []string { func gatherResources(s *state) map[string]interface{} { groups := make(map[string]interface{}, 0) - all_group := allGroup{Vars: make(map[string]string)} + all_group := allGroup{Vars: make(map[string]interface{})} groups["all"] = &all_group for _, res := range s.resources() { @@ -45,7 +45,7 @@ func gatherResources(s *state) map[string]interface{} { if len(s.outputs()) > 0 { for _, out := range s.outputs() { - all_group.Vars[out.keyName] = out.value.(string) + all_group.Vars[out.keyName] = out.value } } return groups @@ -74,7 +74,7 @@ func cmdInventory(stdout io.Writer, stderr io.Writer, s *state) int { writeLn("", stdout, stderr) writeLn("["+group+":vars]", stdout, stderr) for key, item := range grp.Vars { - writeLn(key+"="+item, stdout, stderr) + writeLn(key+"="+item.(string), stdout, stderr) } } diff --git a/parser_test.go b/parser_test.go index 02b116c..3bce4b3 100644 --- a/parser_test.go +++ b/parser_test.go @@ -139,7 +139,15 @@ const exampleStateFile = ` const expectedListOutput = ` { - "all": {"datacenter": "mydc", "olddatacenter": "<0.7_format", "ids": [1, 2, 3, 4], "map": {"key": "value"}}, + "all": { + "hosts": ["10.0.0.1"], + "vars": { + "datacenter": "mydc", + "olddatacenter": "<0.7_format", + "ids": [1, 2, 3, 4], + "map": {"key": "value"} + } + }, "one": ["10.0.0.1", "10.0.1.1"], "two": ["50.0.0.1"], "three": ["192.168.0.3"],