From 7276f41f50e681b68706869915f41e81de6b1246 Mon Sep 17 00:00:00 2001 From: Adam Mckaig Date: Wed, 9 Dec 2015 23:33:40 -0500 Subject: [PATCH] Add integration test for host command --- cli.go | 1 + parser_test.go | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/cli.go b/cli.go index 9d5ed13..577ab4e 100644 --- a/cli.go +++ b/cli.go @@ -21,6 +21,7 @@ func cmdList(stdout io.Writer, stderr io.Writer, s *state) int { // created using the count parameter. groups[res.Name] = append(groups[res.Name], res.Address()) + // Add the instance by its full name, including the counter. groups[res.NameWithCounter()] = []string{res.Address()} } diff --git a/parser_test.go b/parser_test.go index 697aaff..787aca0 100644 --- a/parser_test.go +++ b/parser_test.go @@ -133,8 +133,14 @@ const expectedListOutput = ` } ` -func TestIntegration(t *testing.T) { +const expectedHostOneOutput = ` +{ + "id":"i-aaaaaaaa", + "private_ip":"10.0.0.1" +} +` +func TestListCommand(t *testing.T) { var s state r := strings.NewReader(exampleStateFile) err := s.read(r) @@ -152,6 +158,24 @@ func TestIntegration(t *testing.T) { assert.Equal(t, exp, act) } +func TestHostCommand(t *testing.T) { + var s state + r := strings.NewReader(exampleStateFile) + err := s.read(r) + assert.Nil(t, err) + + // Run the command, capture the output + var stdout, stderr bytes.Buffer + exitCode := cmdHost(&stdout, &stderr, &s, "10.0.0.1") + assert.Equal(t, 0, exitCode) + assert.Equal(t, "", stderr.String()) + + var exp, act interface{} + json.Unmarshal([]byte(expectedHostOneOutput), &exp) + json.Unmarshal([]byte(stdout.String()), &act) + assert.Equal(t, exp, act) +} + func TestStateRead(t *testing.T) { var s state r := strings.NewReader(exampleStateFile)