From c0cc50c81ad9186f260409dc75b9dea5fccd7258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Mej=C3=ADas=20Rodr=C3=ADguez?= Date: Fri, 23 Aug 2019 13:55:30 -0400 Subject: [PATCH] Add unit test for client/portainerTypes.go --- client/portainerTypes_test.go | 101 ++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 client/portainerTypes_test.go diff --git a/client/portainerTypes_test.go b/client/portainerTypes_test.go new file mode 100644 index 0000000..e9adf01 --- /dev/null +++ b/client/portainerTypes_test.go @@ -0,0 +1,101 @@ +package client + +import ( + "testing" + + portainer "github.com/portainer/portainer/api" + "github.com/stretchr/testify/assert" +) + +func TestGetTranslatedStackType(t *testing.T) { + type args struct { + s portainer.Stack + } + tests := []struct { + name string + args args + want string + }{ + { + name: "swarm stack type", + args: args{ + s: portainer.Stack{ + Type: 1, + }, + }, + want: "swarm", + }, + { + name: "compose stack type", + args: args{ + s: portainer.Stack{ + Type: 2, + }, + }, + want: "compose", + }, + { + name: "unknown stack type", + args: args{ + s: portainer.Stack{ + Type: 100, + }, + }, + want: "", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, tt.want, GetTranslatedStackType(tt.args.s)) + }) + } +} + +func TestGenericError_Error(t *testing.T) { + type fields struct { + Err string + Details string + } + tests := []struct { + name string + fields fields + want string + }{ + { + name: "error with message and details", + fields: fields{ + Err: "error", + Details: "details", + }, + want: "error: details", + }, + { + name: "error with message and no details", + fields: fields{ + Err: "error", + }, + want: "error", + }, + { + name: "error with no error message and details", + fields: fields{ + Details: "details", + }, + want: ": details", + }, + { + name: "error with no error message and no details", + fields: fields{}, + want: "", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + e := &GenericError{ + Err: tt.fields.Err, + Details: tt.fields.Details, + } + assert.Equal(t, tt.want, e.Error()) + }) + } +}