mirror of https://github.com/helm/helm
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.
121 lines
2.8 KiB
121 lines
2.8 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"
|
|
|
|
"k8s.io/helm/pkg/helm"
|
|
"k8s.io/helm/pkg/proto/hapi/release"
|
|
)
|
|
|
|
func TestListRun(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
listCmd *listCmd
|
|
expected string
|
|
err bool
|
|
}{
|
|
{
|
|
name: "with a release",
|
|
listCmd: &listCmd{
|
|
client: &fakeReleaseClient{
|
|
rels: []*release.Release{
|
|
releaseMock("thomas-guide"),
|
|
},
|
|
},
|
|
},
|
|
expected: "thomas-guide",
|
|
},
|
|
{
|
|
name: "list --long",
|
|
listCmd: &listCmd{
|
|
client: &fakeReleaseClient{
|
|
rels: []*release.Release{
|
|
releaseMock("atlas"),
|
|
},
|
|
},
|
|
long: true,
|
|
},
|
|
expected: "NAME \tUPDATED \tSTATUS \tCHART \natlas\tFri Sep 2 15:04:05 1977\tDEPLOYED\tfoo-0.1.0-beta.1",
|
|
},
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
for _, tt := range tests {
|
|
tt.listCmd.out = &buf
|
|
err := tt.listCmd.run()
|
|
if (err != nil) != tt.err {
|
|
t.Errorf("%q. expected error: %v, got %v", tt.name, tt.err, err)
|
|
}
|
|
actual := string(bytes.TrimSpace(buf.Bytes()))
|
|
if actual != tt.expected {
|
|
t.Errorf("%q. expected %q, got %q", tt.name, tt.expected, actual)
|
|
}
|
|
buf.Reset()
|
|
}
|
|
}
|
|
|
|
func TestListCmd(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
args []string
|
|
flags map[string]string
|
|
client helm.Interface
|
|
expected string
|
|
err bool
|
|
}{
|
|
{
|
|
name: "with a release",
|
|
client: &fakeReleaseClient{
|
|
rels: []*release.Release{
|
|
releaseMock("thomas-guide"),
|
|
},
|
|
},
|
|
expected: "thomas-guide",
|
|
},
|
|
{
|
|
name: "list --long",
|
|
flags: map[string]string{"long": "1"},
|
|
client: &fakeReleaseClient{
|
|
rels: []*release.Release{
|
|
releaseMock("atlas"),
|
|
},
|
|
},
|
|
expected: "NAME \tUPDATED \tSTATUS \tCHART \natlas\tFri Sep 2 15:04:05 1977\tDEPLOYED\tfoo-0.1.0-beta.1",
|
|
},
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
for _, tt := range tests {
|
|
cmd := newListCmd(tt.client, &buf)
|
|
for flag, value := range tt.flags {
|
|
cmd.Flags().Set(flag, value)
|
|
}
|
|
err := cmd.RunE(cmd, tt.args)
|
|
if (err != nil) != tt.err {
|
|
t.Errorf("%q. expected error: %v, got %v", tt.name, tt.err, err)
|
|
}
|
|
actual := string(bytes.TrimSpace(buf.Bytes()))
|
|
if actual != tt.expected {
|
|
t.Errorf("%q. expected %q, got %q", tt.name, tt.expected, actual)
|
|
}
|
|
buf.Reset()
|
|
}
|
|
}
|