github.com/yoheimuta/protolint@v0.49.8-0.20240515023657-4ecaebb7575d/internal/linter/report/reporters/plainReporter_test.go (about) 1 package reporters_test 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/yoheimuta/go-protoparser/v4/parser/meta" 8 9 "github.com/yoheimuta/protolint/internal/linter/report/reporters" 10 "github.com/yoheimuta/protolint/linter/report" 11 ) 12 13 func TestPlainReporter_Report(t *testing.T) { 14 tests := []struct { 15 name string 16 inputFailures []report.Failure 17 wantOutput string 18 }{ 19 { 20 name: "Prints failures in the plain format", 21 inputFailures: []report.Failure{ 22 report.Failuref( 23 meta.Position{ 24 Filename: "example.proto", 25 Offset: 100, 26 Line: 5, 27 Column: 10, 28 }, 29 "ENUM_NAMES_UPPER_CAMEL_CASE", 30 `EnumField name "fIRST_VALUE" must be CAPITALS_WITH_UNDERSCORES`, 31 ), 32 report.Failuref( 33 meta.Position{ 34 Filename: "example.proto", 35 Offset: 200, 36 Line: 10, 37 Column: 20, 38 }, 39 "ENUM_NAMES_UPPER_CAMEL_CASE", 40 `EnumField name "SECOND.VALUE" must be CAPITALS_WITH_UNDERSCORES`, 41 ), 42 }, 43 wantOutput: `[example.proto:5:10] EnumField name "fIRST_VALUE" must be CAPITALS_WITH_UNDERSCORES 44 [example.proto:10:20] EnumField name "SECOND.VALUE" must be CAPITALS_WITH_UNDERSCORES 45 `, 46 }, 47 } 48 49 for _, test := range tests { 50 test := test 51 t.Run(test.name, func(t *testing.T) { 52 buf := &bytes.Buffer{} 53 err := reporters.PlainReporter{}.Report(buf, test.inputFailures) 54 if err != nil { 55 t.Errorf("got err %v, but want nil", err) 56 return 57 } 58 if buf.String() != test.wantOutput { 59 t.Errorf("got %s, but want %s", buf.String(), test.wantOutput) 60 } 61 }) 62 } 63 }