github.com/codefresh-io/kcfi@v0.0.0-20230301195427-c1578715cc46/cmd/kcfi/show_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 main 18 19 import ( 20 "fmt" 21 "path/filepath" 22 "strings" 23 "testing" 24 25 "helm.sh/helm/v3/pkg/repo/repotest" 26 ) 27 28 func TestShowPreReleaseChart(t *testing.T) { 29 srv, err := repotest.NewTempServer("testdata/testcharts/*.tgz*") 30 if err != nil { 31 t.Fatal(err) 32 } 33 defer srv.Stop() 34 35 if err := srv.LinkIndices(); err != nil { 36 t.Fatal(err) 37 } 38 39 tests := []struct { 40 name string 41 args string 42 flags string 43 fail bool 44 expectedErr string 45 }{ 46 { 47 name: "show pre-release chart", 48 args: "test/pre-release-chart", 49 fail: true, 50 expectedErr: "failed to download \"test/pre-release-chart\"", 51 }, 52 { 53 name: "show pre-release chart with 'devel' flag", 54 args: "test/pre-release-chart", 55 flags: "--devel", 56 fail: false, 57 }, 58 } 59 60 for _, tt := range tests { 61 t.Run(tt.name, func(t *testing.T) { 62 outdir := srv.Root() 63 cmd := fmt.Sprintf("show all '%s' %s --repository-config %s --repository-cache %s", 64 tt.args, 65 tt.flags, 66 filepath.Join(outdir, "repositories.yaml"), 67 outdir, 68 ) 69 //_, out, err := executeActionCommand(cmd) 70 _, _, err := executeActionCommand(cmd) 71 if err != nil { 72 if tt.fail { 73 if !strings.Contains(err.Error(), tt.expectedErr) { 74 t.Errorf("%q expected error: %s, got: %s", tt.name, tt.expectedErr, err.Error()) 75 } 76 return 77 } 78 t.Errorf("%q reported error: %s", tt.name, err) 79 } 80 }) 81 } 82 }