github.com/afking/bazel-gazelle@v0.0.0-20180301150245-c02bc0f529e8/internal/label/labeler_test.go (about) 1 /* Copyright 2017 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 label 17 18 import ( 19 "testing" 20 21 "github.com/bazelbuild/bazel-gazelle/internal/config" 22 ) 23 24 func TestLabelerGo(t *testing.T) { 25 for _, tc := range []struct { 26 name, rel string 27 wantLib, wantBin, wantTest, wantXTest string 28 }{ 29 { 30 name: "root_hierarchical", 31 rel: "", 32 wantLib: "//:go_default_library", 33 wantBin: "//:root", 34 wantTest: "//:go_default_test", 35 wantXTest: "//:go_default_xtest", 36 }, { 37 name: "sub_hierarchical", 38 rel: "sub", 39 wantLib: "//sub:go_default_library", 40 wantBin: "//sub", 41 wantTest: "//sub:go_default_test", 42 wantXTest: "//sub:go_default_xtest", 43 }, 44 } { 45 t.Run(tc.name, func(t *testing.T) { 46 c := &config.Config{} 47 l := NewLabeler(c) 48 49 if got := l.LibraryLabel(tc.rel).String(); got != tc.wantLib { 50 t.Errorf("for library in %s: got %q ; want %q", tc.rel, got, tc.wantLib) 51 } 52 if got := l.BinaryLabel(tc.rel).String(); got != tc.wantBin { 53 t.Errorf("for binary in %s: got %q ; want %q", tc.rel, got, tc.wantBin) 54 } 55 if got := l.TestLabel(tc.rel, false).String(); got != tc.wantTest { 56 t.Errorf("for test in %s: got %q ; want %q", tc.rel, got, tc.wantTest) 57 } 58 if got := l.TestLabel(tc.rel, true).String(); got != tc.wantXTest { 59 t.Errorf("for test in %s: got %q ; want %q", tc.rel, got, tc.wantXTest) 60 } 61 }) 62 } 63 } 64 65 func TestLabelerProto(t *testing.T) { 66 for _, tc := range []struct { 67 desc, rel, name string 68 wantProto, wantGoProto string 69 }{ 70 { 71 desc: "root_hierarchical", 72 rel: "", 73 name: "foo", 74 wantProto: "//:foo_proto", 75 wantGoProto: "//:foo_go_proto", 76 }, { 77 desc: "sub_hierarchical", 78 rel: "sub", 79 name: "foo", 80 wantProto: "//sub:foo_proto", 81 wantGoProto: "//sub:foo_go_proto", 82 }, 83 } { 84 t.Run(tc.desc, func(t *testing.T) { 85 c := &config.Config{} 86 l := NewLabeler(c) 87 88 if got := l.ProtoLabel(tc.rel, tc.name).String(); got != tc.wantProto { 89 t.Errorf("for proto_library in %s: got %q ; want %q", tc.rel, got, tc.wantProto) 90 } 91 if got := l.GoProtoLabel(tc.rel, tc.name).String(); got != tc.wantGoProto { 92 t.Errorf("for go_proto_library in %s: got %q ; want %q", tc.rel, got, tc.wantGoProto) 93 } 94 }) 95 } 96 }