2016-08-09 18:36:00 -04:00
/ *
2018-08-24 15:03:55 -04:00
Copyright The Helm Authors .
2016-08-09 18:36:00 -04:00
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
2025-02-24 10:11:54 -05:00
package cmd
2016-08-09 18:36:00 -04:00
import (
2016-12-02 08:15:36 -05:00
"fmt"
"runtime"
2016-08-09 18:36:00 -04:00
"testing"
)
func TestVerifyCmd ( t * testing . T ) {
2016-12-02 08:15:36 -05:00
2016-12-05 17:59:28 -05:00
statExe := "stat"
statPathMsg := "no such file or directory"
statFileMsg := statPathMsg
2016-12-02 08:15:36 -05:00
if runtime . GOOS == "windows" {
2019-02-01 00:31:09 -05:00
statExe = "FindFirstFile"
2016-12-05 17:59:28 -05:00
statPathMsg = "The system cannot find the path specified."
statFileMsg = "The system cannot find the file specified."
2016-12-02 08:15:36 -05:00
}
2016-08-09 18:36:00 -04:00
tests := [ ] struct {
2018-05-09 11:37:20 -04:00
name string
cmd string
expect string
wantError bool
2016-08-09 18:36:00 -04:00
} {
{
2018-05-09 11:37:20 -04:00
name : "verify requires a chart" ,
cmd : "verify" ,
2018-05-16 12:56:45 -04:00
expect : "\"helm verify\" requires 1 argument\n\nUsage: helm verify PATH [flags]" ,
2018-05-09 11:37:20 -04:00
wantError : true ,
2016-08-09 18:36:00 -04:00
} ,
{
2018-05-09 11:37:20 -04:00
name : "verify requires that chart exists" ,
cmd : "verify no/such/file" ,
expect : fmt . Sprintf ( "%s no/such/file: %s" , statExe , statPathMsg ) ,
wantError : true ,
2016-08-09 18:36:00 -04:00
} ,
{
2018-05-09 11:37:20 -04:00
name : "verify requires that chart is not a directory" ,
cmd : "verify testdata/testcharts/signtest" ,
expect : "unpacked charts cannot be verified" ,
wantError : true ,
2016-08-09 18:36:00 -04:00
} ,
{
2018-05-09 11:37:20 -04:00
name : "verify requires that chart has prov file" ,
cmd : "verify testdata/testcharts/compressedchart-0.1.0.tgz" ,
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 ) ,
wantError : true ,
2016-08-09 18:36:00 -04:00
} ,
{
2018-05-09 11:37:20 -04:00
name : "verify validates a properly signed chart" ,
cmd : "verify testdata/testcharts/signtest-0.1.0.tgz --keyring testdata/helm-test-key.pub" ,
2020-02-28 12:52:21 -05:00
expect : "Signed by: Helm Testing (This key should only be used for testing. DO NOT TRUST.) <helm-testing@helm.sh>\nUsing Key With Fingerprint: 5E615389B53CA37F0EE60BD3843BBF981FC18762\nChart Hash Verified: sha256:e5ef611620fb97704d8751c16bab17fedb68883bfb0edc76f78a70e9173f9b55\n" ,
2018-05-09 11:37:20 -04:00
wantError : false ,
2016-08-09 18:36:00 -04:00
} ,
}
for _ , tt := range tests {
2018-05-09 11:37:20 -04:00
t . Run ( tt . name , func ( t * testing . T ) {
2019-02-08 19:02:57 -05:00
_ , out , err := executeActionCommand ( tt . cmd )
2018-05-09 11:37:20 -04:00
if tt . wantError {
if err == nil {
t . Errorf ( "Expected error, but got none: %q" , out )
}
if err . Error ( ) != tt . expect {
t . Errorf ( "Expected error %q, got %q" , tt . expect , err )
}
return
} else if err != nil {
t . Errorf ( "Unexpected error: %s" , err )
2016-08-09 18:36:00 -04:00
}
2018-05-09 11:37:20 -04:00
if out != tt . expect {
t . Errorf ( "Expected %q, got %q" , tt . expect , out )
2016-08-09 18:36:00 -04:00
}
2018-05-09 11:37:20 -04:00
} )
2016-08-09 18:36:00 -04:00
}
}
2020-08-08 03:43:34 -04:00
func TestVerifyFileCompletion ( t * testing . T ) {
checkFileCompletion ( t , "verify" , true )
checkFileCompletion ( t , "verify mypath" , false )
}