github.com/hydgladiator/helm@v3.0.0-beta.3+incompatible/cmd/helm/verify_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 main 17 18 import ( 19 "fmt" 20 "runtime" 21 "testing" 22 ) 23 24 func TestVerifyCmd(t *testing.T) { 25 26 statExe := "stat" 27 statPathMsg := "no such file or directory" 28 statFileMsg := statPathMsg 29 if runtime.GOOS == "windows" { 30 statExe = "FindFirstFile" 31 statPathMsg = "The system cannot find the path specified." 32 statFileMsg = "The system cannot find the file specified." 33 } 34 35 tests := []struct { 36 name string 37 cmd string 38 expect string 39 wantError bool 40 }{ 41 { 42 name: "verify requires a chart", 43 cmd: "verify", 44 expect: "\"helm verify\" requires 1 argument\n\nUsage: helm verify PATH [flags]", 45 wantError: true, 46 }, 47 { 48 name: "verify requires that chart exists", 49 cmd: "verify no/such/file", 50 expect: fmt.Sprintf("%s no/such/file: %s", statExe, statPathMsg), 51 wantError: true, 52 }, 53 { 54 name: "verify requires that chart is not a directory", 55 cmd: "verify testdata/testcharts/signtest", 56 expect: "unpacked charts cannot be verified", 57 wantError: true, 58 }, 59 { 60 name: "verify requires that chart has prov file", 61 cmd: "verify testdata/testcharts/compressedchart-0.1.0.tgz", 62 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), 63 wantError: true, 64 }, 65 { 66 name: "verify validates a properly signed chart", 67 cmd: "verify testdata/testcharts/signtest-0.1.0.tgz --keyring testdata/helm-test-key.pub", 68 expect: "", 69 wantError: false, 70 }, 71 } 72 73 for _, tt := range tests { 74 t.Run(tt.name, func(t *testing.T) { 75 _, out, err := executeActionCommand(tt.cmd) 76 if tt.wantError { 77 if err == nil { 78 t.Errorf("Expected error, but got none: %q", out) 79 } 80 if err.Error() != tt.expect { 81 t.Errorf("Expected error %q, got %q", tt.expect, err) 82 } 83 return 84 } else if err != nil { 85 t.Errorf("Unexpected error: %s", err) 86 } 87 if out != tt.expect { 88 t.Errorf("Expected %q, got %q", tt.expect, out) 89 } 90 }) 91 } 92 }