github.com/googleapis/api-linter@v1.65.2/rules/aip0191/csharp_namespace_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 "fmt" 19 "testing" 20 21 "github.com/googleapis/api-linter/rules/internal/testutils" 22 ) 23 24 func TestCsharpNamespace(t *testing.T) { 25 for _, test := range []struct { 26 name string 27 CsharpNamespace string 28 problems testutils.Problems 29 }{ 30 {"Valid", "Google.Example.V1", nil}, 31 {"ValidBeta", "Google.Example.V1Beta1", nil}, 32 {"ValidMain", "Google.Example.V1Main", nil}, 33 {"ValidPointBeta", "Google.Example.V1P1Beta1", nil}, 34 {"ValidServiceNamespaceCase", "Google.FooBar.V1", testutils.Problems{}}, 35 {"InvalidBadChars", "Google:Example:V1", testutils.Problems{{Message: "Invalid characters"}}}, 36 {"Invalid", "google.example.v1", testutils.Problems{{ 37 Suggestion: fmt.Sprintf("option csharp_namespace = %q;", "Google.Example.V1"), 38 }}}, 39 {"InvalidVersion", "Google.Example.v1", testutils.Problems{{ 40 Suggestion: fmt.Sprintf("option csharp_namespace = %q;", "Google.Example.V1"), 41 }}}, 42 {"InvalidBeta", "Google.Example.V1beta1", testutils.Problems{{ 43 Suggestion: fmt.Sprintf("option csharp_namespace = %q;", "Google.Example.V1Beta1"), 44 }}}, 45 {"InvalidPointBeta", "Google.Example.V1p1beta1", testutils.Problems{{ 46 Suggestion: fmt.Sprintf("option csharp_namespace = %q;", "Google.Example.V1P1Beta1"), 47 }}}, 48 {"ValidServiceNamespaceCase", "Google.Foobar.V1", testutils.Problems{{Message: "Case"}}}, 49 } { 50 t.Run(test.name, func(t *testing.T) { 51 f := testutils.ParseProto3Tmpl(t, ` 52 package google.example.v1; 53 54 option csharp_namespace = "{{.CsharpNamespace}}"; 55 56 service FooBar {} 57 `, test) 58 if diff := test.problems.SetDescriptor(f).Diff(csharpNamespace.Lint(f)); diff != "" { 59 t.Errorf(diff) 60 } 61 }) 62 } 63 }