github.com/spotmaxtech/k8s-apimachinery-v0260@v0.0.1/pkg/version/helpers_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 version
    18  
    19  import (
    20  	"testing"
    21  )
    22  
    23  func TestCompareKubeAwareVersionStrings(t *testing.T) {
    24  	tests := []*struct {
    25  		v1, v2          string
    26  		expectedGreater bool
    27  	}{
    28  		{"v1", "v2", false},
    29  		{"v2", "v1", true},
    30  		{"v10", "v2", true},
    31  		{"v1", "v2alpha1", true},
    32  		{"v1", "v2beta1", true},
    33  		{"v1alpha2", "v1alpha1", true},
    34  		{"v1beta1", "v2alpha3", true},
    35  		{"v1alpha10", "v1alpha2", true},
    36  		{"v1beta10", "v1beta2", true},
    37  		{"foo", "v1beta2", false},
    38  		{"bar", "foo", true},
    39  		{"version1", "version2", true},  // Non kube-like versions are sorted alphabetically
    40  		{"version1", "version10", true}, // Non kube-like versions are sorted alphabetically
    41  	}
    42  
    43  	for _, tc := range tests {
    44  		if e, a := tc.expectedGreater, CompareKubeAwareVersionStrings(tc.v1, tc.v2) > 0; e != a {
    45  			if e {
    46  				t.Errorf("expected %s to be greater than %s", tc.v1, tc.v2)
    47  			} else {
    48  				t.Errorf("expected %s to be less than %s", tc.v1, tc.v2)
    49  			}
    50  		}
    51  	}
    52  }