github.com/bazelbuild/bazel-gazelle@v0.36.1-0.20240520142334-61b277ba6fed/language/proto/config_test.go (about) 1 /* Copyright 2019 The Bazel Authors. All rights reserved. 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 http://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 16 package proto 17 18 import "testing" 19 20 func TestCheckStripImportPrefix(t *testing.T) { 21 testCases := []struct { 22 name, prefix, rel, wantErr string 23 }{ 24 { 25 name: "not in directory", 26 prefix: "/example.com/idl", 27 rel: "example.com", 28 wantErr: `proto_strip_import_prefix "/example.com/idl" not in directory example.com`, 29 }, 30 { 31 name: "strip prefix at root", 32 prefix: "/include", 33 }, 34 } 35 for _, tc := range testCases { 36 t.Run(tc.name, func(tt *testing.T) { 37 e := checkStripImportPrefix(tc.prefix, tc.rel) 38 if tc.wantErr == "" { 39 if e != nil { 40 t.Errorf("got:\n%v\n\nwant: nil\n", e) 41 } 42 } else { 43 if e == nil || e.Error() != tc.wantErr { 44 t.Errorf("got:\n%v\n\nwant:\n%s\n", e, tc.wantErr) 45 } 46 } 47 }) 48 } 49 }