1
1
mirror of https://github.com/adammck/terraform-inventory synced 2024-11-26 07:43:46 +01:00

Add integration test for host command

This commit is contained in:
Adam Mckaig 2015-12-09 23:33:40 -05:00
parent b43d3f55c2
commit 7276f41f50
2 changed files with 26 additions and 1 deletions

1
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()}
}

@ -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)