mirror of https://github.com/linkerd/linkerd2.git
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package cmd
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/runconduit/conduit/controller/api/public"
|
|
pb "github.com/runconduit/conduit/controller/gen/public"
|
|
)
|
|
|
|
func TestGetPods(t *testing.T) {
|
|
t.Run("Returns names of existing pods if everything went ok", func(t *testing.T) {
|
|
mockClient := &public.MockConduitApiClient{}
|
|
|
|
pods := []*pb.Pod{
|
|
{Name: "pod-a"},
|
|
{Name: "pod-b"},
|
|
{Name: "pod-c"},
|
|
}
|
|
|
|
expectedPodNames := []string{
|
|
"pod-a",
|
|
"pod-b",
|
|
"pod-c",
|
|
}
|
|
response := &pb.ListPodsResponse{
|
|
Pods: pods,
|
|
}
|
|
|
|
mockClient.ListPodsResponseToReturn = response
|
|
actualPodNames, err := getPods(mockClient)
|
|
if err != nil {
|
|
t.Fatalf("Unexpected error: %v", err)
|
|
}
|
|
|
|
for i, actualName := range actualPodNames {
|
|
expectedName := expectedPodNames[i]
|
|
if expectedName != actualName {
|
|
t.Fatalf("Expected %dth element on %v to be [%s], but was [%s]", i, actualPodNames, expectedName, actualName)
|
|
}
|
|
}
|
|
})
|
|
|
|
t.Run("Returns empty list if no pods found", func(t *testing.T) {
|
|
mockClient := &public.MockConduitApiClient{}
|
|
|
|
mockClient.ListPodsResponseToReturn = &pb.ListPodsResponse{
|
|
Pods: []*pb.Pod{},
|
|
}
|
|
|
|
actualPodNames, err := getPods(mockClient)
|
|
if err != nil {
|
|
t.Fatalf("Unexpected error: %v", err)
|
|
}
|
|
|
|
if len(actualPodNames) != 0 {
|
|
t.Fatalf("Expecting no pod names, got %v", actualPodNames)
|
|
}
|
|
})
|
|
|
|
t.Run("Returns error if cant find pods in API", func(t *testing.T) {
|
|
mockClient := &public.MockConduitApiClient{}
|
|
mockClient.ErrorToReturn = errors.New("expected")
|
|
|
|
_, err := getPods(mockClient)
|
|
if err == nil {
|
|
t.Fatalf("Expecting error, got noting")
|
|
}
|
|
})
|
|
}
|