github.com/yrj2011/jx-test-infra@v0.0.0-20190529031832-7a2065ee98eb/prow/clonerefs/options_test.go (about) 1 /* 2 Copyright 2018 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 clonerefs 18 19 import ( 20 "testing" 21 22 "k8s.io/test-infra/prow/kube" 23 ) 24 25 func TestOptions_Validate(t *testing.T) { 26 var testCases = []struct { 27 name string 28 input Options 29 expectedErr bool 30 }{ 31 { 32 name: "all ok", 33 input: Options{ 34 SrcRoot: "test", 35 Log: "thing", 36 GitRefs: []*kube.Refs{ 37 { 38 Repo: "repo1", 39 Org: "org1", 40 }, 41 }, 42 }, 43 expectedErr: false, 44 }, 45 { 46 name: "missing src root", 47 input: Options{ 48 Log: "thing", 49 GitRefs: []*kube.Refs{ 50 { 51 Repo: "repo1", 52 Org: "org1", 53 }, 54 }, 55 }, 56 expectedErr: true, 57 }, 58 { 59 name: "missing Log location", 60 input: Options{ 61 SrcRoot: "test", 62 GitRefs: []*kube.Refs{ 63 { 64 Repo: "repo1", 65 Org: "org1", 66 }, 67 }, 68 }, 69 expectedErr: true, 70 }, 71 { 72 name: "missing refs", 73 input: Options{ 74 SrcRoot: "test", 75 Log: "thing", 76 }, 77 expectedErr: true, 78 }, 79 { 80 name: "separate repos", 81 input: Options{ 82 SrcRoot: "test", 83 Log: "thing", 84 GitRefs: []*kube.Refs{ 85 { 86 Repo: "repo1", 87 Org: "org1", 88 }, 89 { 90 Repo: "repo2", 91 Org: "org2", 92 }, 93 }, 94 }, 95 expectedErr: false, 96 }, 97 { 98 name: "duplicate repos", 99 input: Options{ 100 SrcRoot: "test", 101 Log: "thing", 102 GitRefs: []*kube.Refs{ 103 { 104 Repo: "repo", 105 Org: "org", 106 }, 107 { 108 Repo: "repo", 109 Org: "org", 110 }, 111 }, 112 }, 113 expectedErr: true, 114 }, 115 } 116 117 for _, testCase := range testCases { 118 err := testCase.input.Validate() 119 if testCase.expectedErr && err == nil { 120 t.Errorf("%s: expected an error but got none", testCase.name) 121 } 122 if !testCase.expectedErr && err != nil { 123 t.Errorf("%s: expected no error but got one: %v", testCase.name, err) 124 } 125 } 126 }