github.com/googleapis/api-linter@v1.65.2/rules/aip0191/filenames_test.go (about)

     1  // Copyright 2019 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  // 		https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package aip0191
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/googleapis/api-linter/rules/internal/testutils"
    21  	"github.com/jhump/protoreflect/desc/builder"
    22  )
    23  
    24  func TestFilename(t *testing.T) {
    25  	tests := []struct {
    26  		testName string
    27  		filename string
    28  		problems testutils.Problems
    29  	}{
    30  		{"Valid", "library.proto", testutils.Problems{}},
    31  		{"ValidDirectory", "google/library.proto", testutils.Problems{}},
    32  		{"ValidFileNameWithSnakeCase", "library_test.proto", testutils.Problems{}},
    33  		{"InvalidFileNameNotSnakeCase", "library.test.proto", testutils.Problems{{Message: "invalid characters"}}},
    34  		{"InvalidCharacterUpperCase", "library_Test.proto", testutils.Problems{{Message: "invalid characters"}}},
    35  		{"InvalidCharacterDollar", "library_$test.proto", testutils.Problems{{Message: "invalid characters"}}},
    36  		{"InvalidCharacterSpace", "library test.proto", testutils.Problems{{Message: "invalid characters"}}},
    37  		{"InvalidCharacterHash", "library_#test.proto", testutils.Problems{{Message: "invalid characters"}}},
    38  		{"InvalidStable", "v1.proto", testutils.Problems{{Message: "proto version"}}},
    39  		{"InvalidBigStable", "v20.proto", testutils.Problems{{Message: "proto version"}}},
    40  		{"InvalidStableDirectory", "google/library/v1.proto", testutils.Problems{{Message: "proto version"}}},
    41  		{"InvalidAlphaUnnumbered", "v1alpha.proto", testutils.Problems{{Message: "proto version"}}},
    42  		{"InvalidAlphaNumbered", "v1alpha1.proto", testutils.Problems{{Message: "proto version"}}},
    43  		{"InvalidBetaUnnumbered", "v1beta.proto", testutils.Problems{{Message: "proto version"}}},
    44  		{"InvalidBetaNumbered", "v1beta1.proto", testutils.Problems{{Message: "proto version"}}},
    45  		{"InvalidPoint", "v1p1beta1.proto", testutils.Problems{{Message: "proto version"}}},
    46  	}
    47  	for _, test := range tests {
    48  		t.Run(test.testName, func(t *testing.T) {
    49  			f, err := builder.NewFile(test.filename).Build()
    50  			if err != nil {
    51  				t.Fatalf("Failed to build file.")
    52  			}
    53  			if diff := test.problems.SetDescriptor(f).Diff(filename.Lint(f)); diff != "" {
    54  				t.Errorf(diff)
    55  			}
    56  		})
    57  	}
    58  }