github.com/vmware/govmomi@v0.51.0/cli/flags/version_test.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package flags
     6  
     7  import (
     8  	"reflect"
     9  	"testing"
    10  )
    11  
    12  func TestParseVersion(t *testing.T) {
    13  	type args struct {
    14  		version string
    15  	}
    16  	tests := []struct {
    17  		name    string
    18  		args    args
    19  		want    version
    20  		wantErr bool
    21  	}{
    22  		{name: "5.5.5.5", args: args{version: "5.5.5.5"}, want: version{5, 5, 5, 5}, wantErr: false},
    23  		{name: "0.24.0", args: args{version: "0.24.0"}, want: version{0, 24, 0}, wantErr: false},
    24  		{name: "v0.24.0", args: args{version: "v0.24.0"}, want: version{0, 24, 0}, wantErr: false},
    25  		{name: "v0.24.0-next", args: args{version: "v0.24.0-next"}, want: version{0, 24, 0}, wantErr: false},
    26  		{name: "0.10x", args: args{version: "0.10x"}, want: nil, wantErr: true},
    27  	}
    28  	for _, tt := range tests {
    29  		t.Run(tt.name, func(t *testing.T) {
    30  			got, err := ParseVersion(tt.args.version)
    31  			if (err != nil) != tt.wantErr {
    32  				t.Errorf("ParseVersion() error = %v, wantErr %v", err, tt.wantErr)
    33  				return
    34  			}
    35  			if !reflect.DeepEqual(got, tt.want) {
    36  				t.Errorf("ParseVersion() got = %v, want %v", got, tt.want)
    37  			}
    38  		})
    39  	}
    40  }
    41  
    42  func TestLte(t *testing.T) {
    43  	v1, err := ParseVersion("5.5")
    44  	if err != nil {
    45  		panic(err)
    46  	}
    47  
    48  	v2, err := ParseVersion("5.6")
    49  	if err != nil {
    50  		panic(err)
    51  	}
    52  
    53  	if !v1.Lte(v1) {
    54  		t.Errorf("Expected 5.5 <= 5.5")
    55  	}
    56  
    57  	if !v1.Lte(v2) {
    58  		t.Errorf("Expected 5.5 <= 5.6")
    59  	}
    60  
    61  	if v2.Lte(v1) {
    62  		t.Errorf("Expected not 5.6 <= 5.5")
    63  	}
    64  }