mirror of
https://github.com/adammck/terraform-inventory
synced 2024-11-26 11:53:48 +01:00
Add integration test for host command
This commit is contained in:
parent
b43d3f55c2
commit
7276f41f50
1
cli.go
1
cli.go
@ -21,6 +21,7 @@ func cmdList(stdout io.Writer, stderr io.Writer, s *state) int {
|
|||||||
// created using the count parameter.
|
// created using the count parameter.
|
||||||
groups[res.Name] = append(groups[res.Name], res.Address())
|
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()}
|
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
|
var s state
|
||||||
r := strings.NewReader(exampleStateFile)
|
r := strings.NewReader(exampleStateFile)
|
||||||
err := s.read(r)
|
err := s.read(r)
|
||||||
@ -152,6 +158,24 @@ func TestIntegration(t *testing.T) {
|
|||||||
assert.Equal(t, exp, act)
|
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) {
|
func TestStateRead(t *testing.T) {
|
||||||
var s state
|
var s state
|
||||||
r := strings.NewReader(exampleStateFile)
|
r := strings.NewReader(exampleStateFile)
|
||||||
|
Loading…
Reference in New Issue
Block a user