github.com/werf/3p-helm@v2.8.1+incompatible/cmd/helm/dependency_test.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 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 main 17 18 import ( 19 "bytes" 20 "strings" 21 "testing" 22 ) 23 24 func TestDependencyListCmd(t *testing.T) { 25 26 tests := []struct { 27 name string 28 args []string 29 expect string 30 err bool 31 }{ 32 { 33 name: "No such chart", 34 args: []string{"/no/such/chart"}, 35 err: true, 36 }, 37 { 38 name: "No requirements.yaml", 39 args: []string{"testdata/testcharts/alpine"}, 40 expect: "WARNING: no requirements at ", 41 }, 42 { 43 name: "Requirements in chart dir", 44 args: []string{"testdata/testcharts/reqtest"}, 45 expect: "NAME \tVERSION\tREPOSITORY \tSTATUS \n" + 46 "reqsubchart \t0.1.0 \thttps://example.com/charts\tunpacked\n" + 47 "reqsubchart2\t0.2.0 \thttps://example.com/charts\tunpacked\n" + 48 "reqsubchart3\t>=0.1.0\thttps://example.com/charts\tok \n\n", 49 }, 50 { 51 name: "Requirements in chart archive", 52 args: []string{"testdata/testcharts/reqtest-0.1.0.tgz"}, 53 expect: "NAME \tVERSION\tREPOSITORY \tSTATUS \nreqsubchart \t0.1.0 \thttps://example.com/charts\tmissing\nreqsubchart2\t0.2.0 \thttps://example.com/charts\tmissing\n", 54 }, 55 } 56 57 for _, tt := range tests { 58 buf := bytes.NewBuffer(nil) 59 dlc := newDependencyListCmd(buf) 60 if err := dlc.RunE(dlc, tt.args); err != nil { 61 if tt.err { 62 continue 63 } 64 t.Errorf("Test %q: %s", tt.name, err) 65 continue 66 } 67 68 got := buf.String() 69 if !strings.Contains(got, tt.expect) { 70 t.Errorf("Test: %q, Expected:\n%q\nGot:\n%q", tt.name, tt.expect, got) 71 } 72 } 73 74 }