sigs.k8s.io/cluster-api@v1.7.1/cmd/clusterctl/client/common_test.go (about) 1 /* 2 Copyright 2019 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 client 18 19 import ( 20 "testing" 21 22 . "github.com/onsi/gomega" 23 ) 24 25 func Test_parseProviderName(t *testing.T) { 26 type args struct { 27 provider string 28 } 29 tests := []struct { 30 name string 31 args args 32 wantName string 33 wantVersion string 34 wantErr bool 35 }{ 36 { 37 name: "simple name", 38 args: args{ 39 provider: "provider", 40 }, 41 wantName: "provider", 42 wantVersion: "", 43 wantErr: false, 44 }, 45 { 46 name: "name & version", 47 args: args{ 48 provider: "provider:version", 49 }, 50 wantName: "provider", 51 wantVersion: "version", 52 wantErr: false, 53 }, 54 } 55 for _, tt := range tests { 56 t.Run(tt.name, func(t *testing.T) { 57 g := NewWithT(t) 58 59 gotName, gotVersion, err := parseProviderName(tt.args.provider) 60 if tt.wantErr { 61 g.Expect(err).To(HaveOccurred()) 62 } else { 63 g.Expect(err).ToNot(HaveOccurred()) 64 } 65 g.Expect(gotName).To(Equal(tt.wantName)) 66 67 g.Expect(gotVersion).To(Equal(tt.wantVersion)) 68 }) 69 } 70 }