github.com/yoheimuta/protolint@v0.49.8-0.20240515023657-4ecaebb7575d/internal/linter/report/reporters/unixReporter_test.go (about)

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