github.com/brockwood/helm@v2.8.0-rc.1.0.20180112204834-077be881c4cc+incompatible/cmd/helm/verify_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 "fmt" 21 "runtime" 22 "testing" 23 ) 24 25 func TestVerifyCmd(t *testing.T) { 26 27 statExe := "stat" 28 statPathMsg := "no such file or directory" 29 statFileMsg := statPathMsg 30 if runtime.GOOS == "windows" { 31 statExe = "GetFileAttributesEx" 32 statPathMsg = "The system cannot find the path specified." 33 statFileMsg = "The system cannot find the file specified." 34 } 35 36 tests := []struct { 37 name string 38 args []string 39 flags []string 40 expect string 41 err bool 42 }{ 43 { 44 name: "verify requires a chart", 45 expect: "a path to a package file is required", 46 err: true, 47 }, 48 { 49 name: "verify requires that chart exists", 50 args: []string{"no/such/file"}, 51 expect: fmt.Sprintf("%s no/such/file: %s", statExe, statPathMsg), 52 err: true, 53 }, 54 { 55 name: "verify requires that chart is not a directory", 56 args: []string{"testdata/testcharts/signtest"}, 57 expect: "unpacked charts cannot be verified", 58 err: true, 59 }, 60 { 61 name: "verify requires that chart has prov file", 62 args: []string{"testdata/testcharts/compressedchart-0.1.0.tgz"}, 63 expect: fmt.Sprintf("could not load provenance file testdata/testcharts/compressedchart-0.1.0.tgz.prov: %s testdata/testcharts/compressedchart-0.1.0.tgz.prov: %s", statExe, statFileMsg), 64 err: true, 65 }, 66 { 67 name: "verify validates a properly signed chart", 68 args: []string{"testdata/testcharts/signtest-0.1.0.tgz"}, 69 flags: []string{"--keyring", "testdata/helm-test-key.pub"}, 70 expect: "", 71 err: false, 72 }, 73 } 74 75 for _, tt := range tests { 76 b := bytes.NewBuffer(nil) 77 vc := newVerifyCmd(b) 78 vc.ParseFlags(tt.flags) 79 err := vc.RunE(vc, tt.args) 80 if tt.err { 81 if err == nil { 82 t.Errorf("Expected error, but got none: %q", b.String()) 83 } 84 if err.Error() != tt.expect { 85 t.Errorf("Expected error %q, got %q", tt.expect, err) 86 } 87 continue 88 } else if err != nil { 89 t.Errorf("Unexpected error: %s", err) 90 } 91 if b.String() != tt.expect { 92 t.Errorf("Expected %q, got %q", tt.expect, b.String()) 93 } 94 } 95 }