github.com/GoogleContainerTools/skaffold/v2@v2.13.2/pkg/webhook/labels/labels_test.go (about) 1 /* 2 Copyright 2019 The Skaffold Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package labels 18 19 import ( 20 "testing" 21 22 "github.com/google/go-github/github" 23 24 "github.com/GoogleContainerTools/skaffold/v2/pkg/webhook/constants" 25 "github.com/GoogleContainerTools/skaffold/v2/testutil" 26 ) 27 28 func TestGenerateLabelsFromPR(t *testing.T) { 29 want := map[string]string{ 30 "docs-controller-deployment": "true", 31 "deployment": "docs-controller-deployment-1", 32 } 33 got := GenerateLabelsFromPR(1) 34 35 testutil.CheckDeepEqual(t, want, got) 36 } 37 38 func TestSelector(t *testing.T) { 39 want := "deployment=docs-controller-deployment-1" 40 got := Selector(1) 41 42 testutil.CheckDeepEqual(t, want, got) 43 } 44 45 func TestRetrieveLabel(t *testing.T) { 46 wantKey, wantValue := "deployment", "docs-controller-deployment-1" 47 gotKey, gotValue := RetrieveLabel(1) 48 49 testutil.CheckDeepEqual(t, wantKey, gotKey) 50 testutil.CheckDeepEqual(t, wantValue, gotValue) 51 } 52 53 func TestDocsLabelExists(t *testing.T) { 54 tests := []struct { 55 description string 56 labels []*github.Label 57 expected bool 58 }{ 59 { 60 description: "labels are nil", 61 labels: nil, 62 expected: false, 63 }, 64 { 65 description: "labels are empty", 66 labels: []*github.Label{}, 67 expected: false, 68 }, 69 { 70 description: "doesn't contain the right label", 71 labels: []*github.Label{nil, {Name: github.String("test")}}, 72 expected: false, 73 }, 74 { 75 description: "contains the right label", 76 labels: []*github.Label{{Name: github.String("test")}, {Name: github.String(constants.DocsLabel)}}, 77 expected: true, 78 }, 79 } 80 for _, test := range tests { 81 testutil.Run(t, test.description, func(t *testutil.T) { 82 got := DocsLabelExists(test.labels) 83 84 t.CheckDeepEqual(test.expected, got) 85 }) 86 } 87 }