github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/formatter/checkstyle_test.go (about) 1 package formatter 2 3 import ( 4 "bytes" 5 "testing" 6 7 hcl "github.com/hashicorp/hcl/v2" 8 "github.com/wata727/tflint/tflint" 9 ) 10 11 func Test_checkstylePrint(t *testing.T) { 12 cases := []struct { 13 Name string 14 Issues tflint.Issues 15 Error *tflint.Error 16 Stdout string 17 }{ 18 { 19 Name: "no issues", 20 Issues: tflint.Issues{}, 21 Stdout: `<?xml version="1.0" encoding="UTF-8"?> 22 <checkstyle></checkstyle>`, 23 }, 24 { 25 Name: "issues", 26 Issues: tflint.Issues{ 27 { 28 Rule: &testRule{}, 29 Message: "test", 30 Range: hcl.Range{ 31 Filename: "test.tf", 32 Start: hcl.Pos{Line: 1, Column: 1, Byte: 0}, 33 End: hcl.Pos{Line: 1, Column: 4, Byte: 3}, 34 }, 35 }, 36 }, 37 Stdout: `<?xml version="1.0" encoding="UTF-8"?> 38 <checkstyle> 39 <file name="test.tf"> 40 <error rule="test_rule" line="1" column="1" severity="error" message="test" link="https://github.com"></error> 41 </file> 42 </checkstyle>`, 43 }, 44 } 45 46 for _, tc := range cases { 47 stdout := &bytes.Buffer{} 48 stderr := &bytes.Buffer{} 49 formatter := &Formatter{Stdout: stdout, Stderr: stderr} 50 51 formatter.checkstylePrint(tc.Issues, tc.Error, map[string][]byte{}) 52 53 if stdout.String() != tc.Stdout { 54 t.Fatalf("Failed %s test: expected=%s, stdout=%s", tc.Name, tc.Stdout, stdout.String()) 55 } 56 } 57 }