mirror of
https://github.com/hanzoai/cd.git
synced 2026-10-30 14:56:45 +00:00
go fix applied the modernizers: promoted-field keys in struct literals,
strings.Cut, SplitSeq, new(expr), slices and maps helpers, wg.Go, reflect.TypeFor
and errors.AsType. omitzero is left out, since omitting a zero struct such as
time.Time{} is a per-field wire decision and not a mechanical one.
Two changes the modernizers could not make for themselves. AsType needs its type
argument to be an error, so the git exit-status reader embeds error in the
interface it asks for. And an error built by concatenating a tag list into its
own format string now says so with a verb, which is what vet was pointing at.
Co-authored-by: Hanzo Dev <[email protected]>
78 lines
1.8 KiB
Go
78 lines
1.8 KiB
Go
package kube
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
corev1 "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/client-go/kubernetes/fake"
|
|
)
|
|
|
|
func Test_selectPodForPortForward(t *testing.T) {
|
|
// Mock the Kubernetes client
|
|
client := fake.NewSimpleClientset(
|
|
&corev1.Pod{
|
|
Name: "test-pod",
|
|
Namespace: "default",
|
|
Labels: map[string]string{
|
|
"app": "test-app",
|
|
},
|
|
Status: corev1.PodStatus{
|
|
Conditions: []corev1.PodCondition{
|
|
{
|
|
Type: corev1.PodReady,
|
|
Status: corev1.ConditionTrue,
|
|
LastTransitionTime: metav1.Now(),
|
|
},
|
|
},
|
|
Phase: corev1.PodRunning,
|
|
},
|
|
},
|
|
&corev1.Pod{
|
|
Name: "test2-pod-broken",
|
|
Namespace: "default",
|
|
Labels: map[string]string{
|
|
"app": "test2",
|
|
},
|
|
Status: corev1.PodStatus{
|
|
Conditions: []corev1.PodCondition{
|
|
{
|
|
Type: corev1.PodReady,
|
|
Status: corev1.ConditionFalse,
|
|
LastTransitionTime: metav1.Now(),
|
|
},
|
|
},
|
|
Phase: corev1.PodFailed,
|
|
},
|
|
},
|
|
&corev1.Pod{
|
|
Name: "test2-pod-working",
|
|
Namespace: "default",
|
|
Labels: map[string]string{
|
|
"app": "test2",
|
|
},
|
|
Status: corev1.PodStatus{
|
|
Conditions: []corev1.PodCondition{
|
|
{
|
|
Type: corev1.PodReady,
|
|
Status: corev1.ConditionTrue,
|
|
LastTransitionTime: metav1.Now(),
|
|
},
|
|
},
|
|
Phase: corev1.PodRunning,
|
|
},
|
|
},
|
|
)
|
|
|
|
// Test selecting the pod
|
|
selectedPod, err := selectPodForPortForward(client, "default", "app=test-app")
|
|
require.NoError(t, err)
|
|
require.Equal(t, "test-pod", selectedPod.Name)
|
|
|
|
// Test selecting the working pod
|
|
selectedPod2, err := selectPodForPortForward(client, "default", "app=test2")
|
|
require.NoError(t, err)
|
|
require.Equal(t, "test2-pod-working", selectedPod2.Name)
|
|
}
|