forked from terraform-linters/tflint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_test.go
60 lines (52 loc) · 1.26 KB
/
integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"os"
"reflect"
"sort"
"strings"
"testing"
"github.com/k0kubun/pp"
"github.com/wata727/tflint/issue"
)
func TestIntegration(t *testing.T) {
cases := []struct {
Name string
Command string
Dir string
}{
{
Name: "general",
Command: "./tflint --format json",
Dir: "general",
},
}
for _, tc := range cases {
dir, _ := os.Getwd()
testDir := dir + "/integration/" + tc.Dir
os.Chdir(testDir)
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := &CLI{
outStream: outStream,
errStream: errStream,
}
args := strings.Split(tc.Command, " ")
cli.Run(args)
b, _ := ioutil.ReadFile("result.json")
var expectedIssues []*issue.Issue
if err := json.Unmarshal(b, &expectedIssues); err != nil {
t.Fatal(err)
}
sort.Sort(issue.ByFileLine{Issues: issue.Issues(expectedIssues)})
var resultIssues []*issue.Issue
if err := json.Unmarshal(outStream.Bytes(), &resultIssues); err != nil {
t.Fatal(err)
}
sort.Sort(issue.ByFileLine{Issues: issue.Issues(resultIssues)})
if !reflect.DeepEqual(resultIssues, expectedIssues) {
t.Fatalf("\nBad: %s\nExpected: %s\n\ntestcase: %s", pp.Sprint(resultIssues), pp.Sprint(expectedIssues), tc.Name)
}
}
}