mirror of
https://github.com/adammck/terraform-inventory
synced 2024-11-26 11:53:48 +01:00
Add integration test
This commit is contained in:
parent
a212fb68b7
commit
6d362d3e2a
@ -1,9 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
const exampleStateFile = `
|
const exampleStateFile = `
|
||||||
@ -101,6 +104,43 @@ const exampleStateFile = `
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const expectedListOutput = `
|
||||||
|
{
|
||||||
|
"one": ["10.0.0.1"],
|
||||||
|
"two": ["50.0.0.1"],
|
||||||
|
"three": ["192.168.0.3"],
|
||||||
|
"four": ["10.2.1.5"],
|
||||||
|
"five": ["10.20.30.40"],
|
||||||
|
"six": ["10.120.0.226"],
|
||||||
|
|
||||||
|
"one.0": ["10.0.0.1"],
|
||||||
|
"two.0": ["50.0.0.1"],
|
||||||
|
"three.0": ["192.168.0.3"],
|
||||||
|
"four.0": ["10.2.1.5"],
|
||||||
|
"five.0": ["10.20.30.40"],
|
||||||
|
"six.0": ["10.120.0.226"]
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
func TestIntegration(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 := cmdList(&stdout, &stderr, &s)
|
||||||
|
assert.Equal(t, 0, exitCode)
|
||||||
|
assert.Equal(t, "", stderr.String())
|
||||||
|
|
||||||
|
var exp, act interface{}
|
||||||
|
json.Unmarshal([]byte(expectedListOutput), &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