github.com/fluxcd/go-git-providers@v0.19.3/gitprovider/gitprovider_test.go (about) 1 /* 2 Copyright 2020 The Flux CD contributors. 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 gitprovider 18 19 import ( 20 "reflect" 21 "testing" 22 ) 23 24 func TestValidateAndDefaultInfo(t *testing.T) { 25 tests := []struct { 26 name string 27 info DefaultedInfoRequest 28 expected DefaultedInfoRequest 29 wantErr bool 30 }{ 31 { 32 name: "valid => defaulting", 33 info: &TeamAccessInfo{ 34 Name: "foo", 35 }, 36 expected: &TeamAccessInfo{ 37 Name: "foo", 38 Permission: RepositoryPermissionVar(defaultRepoPermission), 39 }, 40 wantErr: false, 41 }, 42 { 43 name: "invalid => no defaulting + error", 44 info: &TeamAccessInfo{}, 45 expected: &TeamAccessInfo{}, 46 wantErr: true, 47 }, 48 } 49 for _, tt := range tests { 50 t.Run(tt.name, func(t *testing.T) { 51 if err := ValidateAndDefaultInfo(tt.info); (err != nil) != tt.wantErr { 52 t.Errorf("ValidateAndDefaultInfo() error = %v, wantErr %v", err, tt.wantErr) 53 } 54 if !reflect.DeepEqual(tt.info, tt.expected) { 55 t.Errorf("ValidateAndDefaultInfo() object = %v, wanted %v", tt.info, tt.expected) 56 } 57 }) 58 } 59 }