Skip to content

Commit

Permalink
test(kubernetes): validate list output type
Browse files Browse the repository at this point in the history
  • Loading branch information
kangasta committed Oct 17, 2023
1 parent b9c2fc2 commit 9315c94
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions internal/commands/kubernetes/list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package kubernetes

import (
"testing"

"github.com/UpCloudLtd/upcloud-cli/v2/internal/commands"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/config"
smock "github.com/UpCloudLtd/upcloud-cli/v2/internal/mock"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/mockexecute"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/testutils"

"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestList_MarshaledOutput(t *testing.T) {
cluster1 := upcloud.KubernetesCluster{
ControlPlaneIPFilter: []string{"10.144.1.100", "10.144.2.0/24"},
Name: "upcloud-go-sdk-unit-test",
Network: "03a98be3-7daa-443f-bb25-4bc6854b396c",
NetworkCIDR: "172.16.1.0/24",
NodeGroups: []upcloud.KubernetesNodeGroup{
{
Count: 4,
Labels: []upcloud.Label{
{
Key: "managedBy",
Value: "upcloud-go-sdk-unit-test",
},
{
Key: "another",
Value: "label-thing",
},
},
Name: "upcloud-go-sdk-unit-test",
Plan: "2xCPU-4GB",
State: upcloud.KubernetesNodeGroupStateRunning,
KubeletArgs: []upcloud.KubernetesKubeletArg{
{
Key: "somekubeletkey",
Value: "somekubeletvalue",
},
},
Taints: []upcloud.KubernetesTaint{
{
Effect: "NoExecute",
Key: "sometaintkey",
Value: "sometaintvalue",
},
{
Effect: "NoExecute",
Key: "sometaintkey",
Value: "sometaintvalue",
},
{
Effect: "NoExecute",
Key: "sometaintkey",
Value: "sometaintvalue",
},
},
Storage: "storage-uuid",
SSHKeys: []string{"somekey"},
UtilityNetworkAccess: true,
}, {
Count: 8,
Labels: []upcloud.Label{
{
Key: "managedBy",
Value: "upcloud-go-sdk-unit-test-2",
},
{
Key: "another2",
Value: "label-thing-2",
},
},
Name: "upcloud-go-sdk-unit-test-2",
Plan: "4xCPU-8GB",
State: upcloud.KubernetesNodeGroupStatePending,
KubeletArgs: []upcloud.KubernetesKubeletArg{
{
Key: "somekubeletkey2",
Value: "somekubeletvalue2",
},
},
Taints: []upcloud.KubernetesTaint{
{
Effect: "NoSchedule",
Key: "sometaintkey2",
Value: "sometaintvalue2",
},
},
Storage: "storage-uuid-2",
SSHKeys: []string{"somekey2"},
UtilityNetworkAccess: false,
},
},
State: upcloud.KubernetesClusterStateRunning,
UUID: "0ddab8f4-97c0-4222-91ba-85a4fff7499b",
Zone: "de-fra1",
}

mService := smock.Service{}
mService.On("GetKubernetesClusters", mock.Anything).Return([]upcloud.KubernetesCluster{cluster1}, nil)

conf := config.New()
conf.Viper().Set(config.KeyOutput, config.ValueOutputJSON)

command := commands.BuildCommand(ListCommand(), nil, conf)

output, err := mockexecute.MockExecute(command, &mService, conf)

assert.Nil(t, err)
testutils.AssertOutputIsList(t, output)
}

0 comments on commit 9315c94

Please sign in to comment.