k8s.io/test-infra@v0.0.0-20240520184403-27c6b4c223d8/robots/pr-creator/main_test.go (about) 1 /* 2 Copyright 2021 The Kubernetes 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 main 18 19 import ( 20 "reflect" 21 "testing" 22 23 "sigs.k8s.io/prow/pkg/flagutil" 24 ) 25 26 func Test_options_getLabels(t *testing.T) { 27 type fields struct { 28 github flagutil.GitHubOptions 29 branch string 30 allowMods bool 31 confirm bool 32 local bool 33 org string 34 repo string 35 source string 36 title string 37 headBranch string 38 matchTitle string 39 body string 40 labels string 41 } 42 tests := []struct { 43 name string 44 fields fields 45 want []string 46 }{ 47 { 48 name: "empty labels", 49 fields: fields{ 50 github: flagutil.GitHubOptions{}, 51 branch: "", 52 allowMods: false, 53 confirm: false, 54 local: false, 55 org: "", 56 repo: "", 57 source: "", 58 title: "", 59 headBranch: "", 60 matchTitle: "", 61 body: "", 62 labels: "", 63 }, 64 want: nil, 65 }, 66 { 67 name: "one label", 68 fields: fields{ 69 github: flagutil.GitHubOptions{}, 70 branch: "", 71 allowMods: false, 72 confirm: false, 73 local: false, 74 org: "", 75 repo: "", 76 source: "", 77 title: "", 78 headBranch: "", 79 matchTitle: "", 80 body: "", 81 labels: "lgtm", 82 }, 83 want: []string{ 84 "lgtm", 85 }, 86 }, 87 { 88 name: "two labels", 89 fields: fields{ 90 github: flagutil.GitHubOptions{}, 91 branch: "", 92 allowMods: false, 93 confirm: false, 94 local: false, 95 org: "", 96 repo: "", 97 source: "", 98 title: "", 99 headBranch: "", 100 matchTitle: "", 101 body: "", 102 labels: "lgtm,approve", 103 }, 104 want: []string{ 105 "lgtm", 106 "approve", 107 }, 108 }, 109 } 110 111 for _, tt := range tests { 112 t.Run(tt.name, func(t *testing.T) { 113 o := options{ 114 github: tt.fields.github, 115 branch: tt.fields.branch, 116 allowMods: tt.fields.allowMods, 117 confirm: tt.fields.confirm, 118 local: tt.fields.local, 119 org: tt.fields.org, 120 repo: tt.fields.repo, 121 source: tt.fields.source, 122 title: tt.fields.title, 123 headBranch: tt.fields.headBranch, 124 matchTitle: tt.fields.matchTitle, 125 body: tt.fields.body, 126 labels: tt.fields.labels, 127 } 128 if got := o.getLabels(); !reflect.DeepEqual(got, tt.want) { 129 t.Errorf("getLabels() = %v, want %v", got, tt.want) 130 } 131 }) 132 } 133 134 }