github.com/uhthomas/helm@v3.0.0-beta.3+incompatible/pkg/action/chart_save_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 action 18 19 import ( 20 "io/ioutil" 21 "testing" 22 23 "helm.sh/helm/internal/experimental/registry" 24 ) 25 26 func chartSaveAction(t *testing.T) *ChartSave { 27 t.Helper() 28 config := actionConfigFixture(t) 29 action := NewChartSave(config) 30 return action 31 } 32 33 func TestChartSave(t *testing.T) { 34 action := chartSaveAction(t) 35 36 input := buildChart() 37 if err := action.Run(ioutil.Discard, input, "localhost:5000/test:0.2.0"); err != nil { 38 t.Error(err) 39 } 40 41 ref, err := registry.ParseReference("localhost:5000/test:0.2.0") 42 if err != nil { 43 t.Fatal(err) 44 } 45 46 if _, err := action.cfg.RegistryClient.LoadChart(ref); err != nil { 47 t.Error(err) 48 } 49 50 // now let's check if `helm chart save` can use the chart version when the tag is not present 51 if err := action.Run(ioutil.Discard, input, "localhost:5000/test"); err != nil { 52 t.Error(err) 53 } 54 55 ref, err = registry.ParseReference("localhost:5000/test") 56 if err != nil { 57 t.Fatal(err) 58 } 59 60 // TODO: guess latest based on semver? 61 _, err = action.cfg.RegistryClient.LoadChart(ref) 62 if err == nil { 63 t.Error("Expected error parsing ref without tag") 64 } 65 66 ref.Tag = "0.1.0" 67 if _, err := action.cfg.RegistryClient.LoadChart(ref); err != nil { 68 t.Error(err) 69 } 70 }