github.com/tetrafolium/tflint@v0.8.0/printer/checkstyle_test.go (about) 1 package printer 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/wata727/tflint/issue" 8 ) 9 10 func TestCheckstylePrint(t *testing.T) { 11 cases := []struct { 12 Name string 13 Input []*issue.Issue 14 Result string 15 }{ 16 { 17 Name: "no issues", 18 Input: []*issue.Issue{}, 19 Result: `<?xml version="1.0" encoding="UTF-8"?> 20 <checkstyle></checkstyle>`, 21 }, 22 { 23 Name: "multi files", 24 Input: []*issue.Issue{ 25 { 26 Detector: "error detector", 27 File: "template.tf", 28 Line: 1, 29 Type: "ERROR", 30 Message: "example error message", 31 }, 32 { 33 Detector: "notice detector", 34 File: "application.tf", 35 Line: 10, 36 Type: "NOTICE", 37 Message: "example notice message", 38 Link: "https://github.com/wata727/tflint", 39 }, 40 { 41 Detector: "warning detector", 42 File: "template.tf", 43 Line: 3, 44 Type: "WARNING", 45 Message: "example warning message", 46 }, 47 }, 48 Result: `<?xml version="1.0" encoding="UTF-8"?> 49 <checkstyle> 50 <file name="application.tf"> 51 <error detector="notice detector" line="10" severity="info" message="example notice message" link="https://github.com/wata727/tflint"></error> 52 </file> 53 <file name="template.tf"> 54 <error detector="error detector" line="1" severity="error" message="example error message" link=""></error> 55 <error detector="warning detector" line="3" severity="warning" message="example warning message" link=""></error> 56 </file> 57 </checkstyle>`, 58 }, 59 } 60 61 for _, tc := range cases { 62 stdout := &bytes.Buffer{} 63 stderr := &bytes.Buffer{} 64 p := NewPrinter(stdout, stderr) 65 p.CheckstylePrint(tc.Input) 66 result := stdout.String() 67 68 if result != tc.Result { 69 t.Fatalf("\nBad: %s\nExpected: %s\n\ntestcase: %s", result, tc.Result, tc.Name) 70 } 71 } 72 }