github.com/vmware/govmomi@v0.43.0/govc/flags/version_test.go (about) 1 /* 2 Copyright (c) 2014 VMware, Inc. All Rights Reserved. 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 flags 18 19 import ( 20 "reflect" 21 "testing" 22 ) 23 24 func TestParseVersion(t *testing.T) { 25 type args struct { 26 version string 27 } 28 tests := []struct { 29 name string 30 args args 31 want version 32 wantErr bool 33 }{ 34 {name: "5.5.5.5", args: args{version: "5.5.5.5"}, want: version{5, 5, 5, 5}, wantErr: false}, 35 {name: "0.24.0", args: args{version: "0.24.0"}, want: version{0, 24, 0}, wantErr: false}, 36 {name: "v0.24.0", args: args{version: "v0.24.0"}, want: version{0, 24, 0}, wantErr: false}, 37 {name: "v0.24.0-next", args: args{version: "v0.24.0-next"}, want: version{0, 24, 0}, wantErr: false}, 38 {name: "0.10x", args: args{version: "0.10x"}, want: nil, wantErr: true}, 39 } 40 for _, tt := range tests { 41 t.Run(tt.name, func(t *testing.T) { 42 got, err := ParseVersion(tt.args.version) 43 if (err != nil) != tt.wantErr { 44 t.Errorf("ParseVersion() error = %v, wantErr %v", err, tt.wantErr) 45 return 46 } 47 if !reflect.DeepEqual(got, tt.want) { 48 t.Errorf("ParseVersion() got = %v, want %v", got, tt.want) 49 } 50 }) 51 } 52 } 53 54 func TestLte(t *testing.T) { 55 v1, err := ParseVersion("5.5") 56 if err != nil { 57 panic(err) 58 } 59 60 v2, err := ParseVersion("5.6") 61 if err != nil { 62 panic(err) 63 } 64 65 if !v1.Lte(v1) { 66 t.Errorf("Expected 5.5 <= 5.5") 67 } 68 69 if !v1.Lte(v2) { 70 t.Errorf("Expected 5.5 <= 5.6") 71 } 72 73 if v2.Lte(v1) { 74 t.Errorf("Expected not 5.6 <= 5.5") 75 } 76 } 77 78 func TestDevelopmentVersion(t *testing.T) { 79 if !isDevelopmentVersion("6.5.x") { 80 t.Error("expected true") 81 } 82 83 if !isDevelopmentVersion("r4A70F") { 84 t.Error("expected true") 85 } 86 87 if isDevelopmentVersion("6.5") { 88 t.Error("expected false") 89 } 90 }