blob: 0fcb904271308175caed671e06ed7268e8df5dbd [file] [log] [blame]
Rupert Shuttleworth2e4219b2021-03-12 11:04:21 +00001// Copyright 2021 Google Inc. 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
15package bazel
16
17import (
18 "reflect"
19 "testing"
20)
21
22func TestUniqueBazelLabels(t *testing.T) {
23 testCases := []struct {
24 originalLabels []Label
25 expectedUniqueLabels []Label
26 }{
27 {
28 originalLabels: []Label{
29 {Label: "a"},
30 {Label: "b"},
31 {Label: "a"},
32 {Label: "c"},
33 },
34 expectedUniqueLabels: []Label{
35 {Label: "a"},
36 {Label: "b"},
37 {Label: "c"},
38 },
39 },
40 }
41 for _, tc := range testCases {
42 actualUniqueLabels := UniqueBazelLabels(tc.originalLabels)
43 if !reflect.DeepEqual(tc.expectedUniqueLabels, actualUniqueLabels) {
44 t.Fatalf("Expected %v, got %v", tc.expectedUniqueLabels, actualUniqueLabels)
45 }
46 }
47}
48
49func TestUniqueBazelLabelList(t *testing.T) {
50 testCases := []struct {
51 originalLabelList LabelList
52 expectedUniqueLabelList LabelList
53 }{
54 {
55 originalLabelList: LabelList{
56 Includes: []Label{
57 {Label: "a"},
58 {Label: "b"},
59 {Label: "a"},
60 {Label: "c"},
61 },
62 Excludes: []Label{
63 {Label: "x"},
64 {Label: "x"},
65 {Label: "y"},
66 {Label: "z"},
67 },
68 },
69 expectedUniqueLabelList: LabelList{
70 Includes: []Label{
71 {Label: "a"},
72 {Label: "b"},
73 {Label: "c"},
74 },
75 Excludes: []Label{
76 {Label: "x"},
77 {Label: "y"},
78 {Label: "z"},
79 },
80 },
81 },
82 }
83 for _, tc := range testCases {
84 actualUniqueLabelList := UniqueBazelLabelList(tc.originalLabelList)
85 if !reflect.DeepEqual(tc.expectedUniqueLabelList, actualUniqueLabelList) {
86 t.Fatalf("Expected %v, got %v", tc.expectedUniqueLabelList, actualUniqueLabelList)
87 }
88 }
89}