github.com/stefanmcshane/helm@v0.0.0-20221213002717-88a4a2c6e77d/pkg/chartutil/capabilities_test.go (about) 1 /* 2 Copyright The Helm Authors. 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 */ 15 16 package chartutil 17 18 import ( 19 "testing" 20 ) 21 22 func TestVersionSet(t *testing.T) { 23 vs := VersionSet{"v1", "apps/v1"} 24 if d := len(vs); d != 2 { 25 t.Errorf("Expected 2 versions, got %d", d) 26 } 27 28 if !vs.Has("apps/v1") { 29 t.Error("Expected to find apps/v1") 30 } 31 32 if vs.Has("Spanish/inquisition") { 33 t.Error("No one expects the Spanish/inquisition") 34 } 35 } 36 37 func TestDefaultVersionSet(t *testing.T) { 38 if !DefaultVersionSet.Has("v1") { 39 t.Error("Expected core v1 version set") 40 } 41 } 42 43 func TestDefaultCapabilities(t *testing.T) { 44 kv := DefaultCapabilities.KubeVersion 45 if kv.String() != "v1.20.0" { 46 t.Errorf("Expected default KubeVersion.String() to be v1.20.0, got %q", kv.String()) 47 } 48 if kv.Version != "v1.20.0" { 49 t.Errorf("Expected default KubeVersion.Version to be v1.20.0, got %q", kv.Version) 50 } 51 if kv.GitVersion() != "v1.20.0" { 52 t.Errorf("Expected default KubeVersion.GitVersion() to be v1.20.0, got %q", kv.Version) 53 } 54 if kv.Major != "1" { 55 t.Errorf("Expected default KubeVersion.Major to be 1, got %q", kv.Major) 56 } 57 if kv.Minor != "20" { 58 t.Errorf("Expected default KubeVersion.Minor to be 20, got %q", kv.Minor) 59 } 60 } 61 62 func TestDefaultCapabilitiesHelmVersion(t *testing.T) { 63 hv := DefaultCapabilities.HelmVersion 64 65 if hv.Version != "v3.10" { 66 t.Errorf("Expected default HelmVersion to be v3.10, got %q", hv.Version) 67 } 68 } 69 70 func TestParseKubeVersion(t *testing.T) { 71 kv, err := ParseKubeVersion("v1.16.0") 72 if err != nil { 73 t.Errorf("Expected v1.16.0 to parse successfully") 74 } 75 if kv.Version != "v1.16.0" { 76 t.Errorf("Expected parsed KubeVersion.Version to be v1.16.0, got %q", kv.String()) 77 } 78 if kv.Major != "1" { 79 t.Errorf("Expected parsed KubeVersion.Major to be 1, got %q", kv.Major) 80 } 81 if kv.Minor != "16" { 82 t.Errorf("Expected parsed KubeVersion.Minor to be 16, got %q", kv.Minor) 83 } 84 }