Change GetTranslatedStackType to use StackType instead of Stack

This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-08-23 14:07:06 -04:00
parent c0cc50c81a
commit f82f116e1b
4 changed files with 11 additions and 17 deletions

View File

@ -7,11 +7,11 @@ import (
)
// GetTranslatedStackType returns a stack's Type field (int) translated to it's human readable form (string)
func GetTranslatedStackType(s portainer.Stack) string {
switch s.Type {
case 1:
func GetTranslatedStackType(t portainer.StackType) string {
switch t {
case portainer.DockerSwarmStack:
return "swarm"
case 2:
case portainer.DockerComposeStack:
return "compose"
default:
return ""

View File

@ -9,7 +9,7 @@ import (
func TestGetTranslatedStackType(t *testing.T) {
type args struct {
s portainer.Stack
t portainer.StackType
}
tests := []struct {
name string
@ -19,34 +19,28 @@ func TestGetTranslatedStackType(t *testing.T) {
{
name: "swarm stack type",
args: args{
s: portainer.Stack{
Type: 1,
},
t: portainer.DockerSwarmStack,
},
want: "swarm",
},
{
name: "compose stack type",
args: args{
s: portainer.Stack{
Type: 2,
},
t: portainer.DockerComposeStack,
},
want: "compose",
},
{
name: "unknown stack type",
args: args{
s: portainer.Stack{
Type: 100,
},
t: 100,
},
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, GetTranslatedStackType(tt.args.s))
assert.Equal(t, tt.want, GetTranslatedStackType(tt.args.t))
})
}
}

View File

@ -87,7 +87,7 @@ var stackInspectCmd = &cobra.Command{
"%v\t%s\t%v\t%s",
stack.ID,
stack.Name,
client.GetTranslatedStackType(stack),
client.GetTranslatedStackType(stack.Type),
endpoint.Name,
))
common.CheckError(err)

View File

@ -89,7 +89,7 @@ var stackListCmd = &cobra.Command{
"%v\t%s\t%v\t%s",
s.ID,
s.Name,
client.GetTranslatedStackType(s),
client.GetTranslatedStackType(s.Type),
stackEndpoint.Name,
))
common.CheckError(err)