You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
helm/cmd/helm/verify_test.go

84 lines
2.3 KiB

/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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.
*/
package main
import (
"bytes"
"testing"
)
func TestVerifyCmd(t *testing.T) {
tests := []struct {
name string
args []string
flags []string
expect string
err bool
}{
{
name: "verify requires a chart",
expect: "a path to a package file is required",
err: true,
},
{
name: "verify requires that chart exists",
args: []string{"no/such/file"},
expect: "stat no/such/file: no such file or directory",
err: true,
},
{
name: "verify requires that chart is not a directory",
args: []string{"testdata/testcharts/signtest"},
expect: "unpacked charts cannot be verified",
err: true,
},
{
name: "verify requires that chart has prov file",
args: []string{"testdata/testcharts/compressedchart-0.1.0.tgz"},
expect: "could not load provenance file testdata/testcharts/compressedchart-0.1.0.tgz.prov: stat testdata/testcharts/compressedchart-0.1.0.tgz.prov: no such file or directory",
err: true,
},
{
name: "verify validates a properly signed chart",
args: []string{"testdata/testcharts/signtest-0.1.0.tgz"},
flags: []string{"--keyring", "testdata/helm-test-key.pub"},
expect: "",
err: false,
},
}
for _, tt := range tests {
b := bytes.NewBuffer(nil)
vc := newVerifyCmd(b)
vc.ParseFlags(tt.flags)
err := vc.RunE(vc, tt.args)
if tt.err {
if err == nil {
t.Errorf("Expected error, but got none: %q", b.String())
}
if err.Error() != tt.expect {
t.Errorf("Expected error %q, got %q", tt.expect, err)
}
continue
} else if err != nil {
t.Errorf("Unexpected error: %s", err)
}
if b.String() != tt.expect {
t.Errorf("Expected %q, got %q", tt.expect, b.String())
}
}
}