github.com/zsuzhengdu/helm@v3.0.0-beta.3+incompatible/pkg/chartutil/compatible_test.go (about)

     1  /*
     2  Copyright The Helm 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 represents the current version of the project.
    18  package chartutil
    19  
    20  import "testing"
    21  
    22  func TestIsCompatibleRange(t *testing.T) {
    23  	tests := []struct {
    24  		constraint string
    25  		ver        string
    26  		expected   bool
    27  	}{
    28  		{"v2.0.0-alpha.4", "v2.0.0-alpha.4", true},
    29  		{"v2.0.0-alpha.3", "v2.0.0-alpha.4", false},
    30  		{"v2.0.0", "v2.0.0-alpha.4", false},
    31  		{"v2.0.0-alpha.4", "v2.0.0", false},
    32  		{"~v2.0.0", "v2.0.1", true},
    33  		{"v2", "v2.0.0", true},
    34  		{">2.0.0", "v2.1.1", true},
    35  		{"v2.1.*", "v2.1.1", true},
    36  	}
    37  
    38  	for _, tt := range tests {
    39  		if IsCompatibleRange(tt.constraint, tt.ver) != tt.expected {
    40  			t.Errorf("expected constraint %s to be %v for %s", tt.constraint, tt.expected, tt.ver)
    41  		}
    42  	}
    43  }