Skip to content

Commit

Permalink
test: add tests for standalone pods
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-- committed Nov 25, 2024
1 parent bb83f83 commit 0778a47
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/skaffold/kubernetes/status/resource/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ func (r *Resource) CheckStatus(ctx context.Context, cfg kubectl.Config) {
// See https://github.com/GoogleCloudPlatform/cloud-code-vscode-internal/issues/5277
if ae.ErrCode == proto.StatusCode_STATUSCHECK_SUCCESS {
for _, pod := range r.resources {
if pod.Status() == "Succeeded" {
continue // Skip terminated pods
}

eventV2.ResourceStatusCheckEventCompletedMessage(
pod.String(),
fmt.Sprintf("%s %s: running.\n", tabHeader, pod.String()),
Expand Down
52 changes: 52 additions & 0 deletions pkg/skaffold/kubernetes/status/resource/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,58 @@ func TestDeploymentCheckStatus(t *testing.T) {
}
}

func TestStandalonePodsCheckStatus(t *testing.T) {
ns := "test-ns"
tests := []struct {
description string
podStatus string
expectedMessage string
expectedErrCode proto.StatusCode
}{
{
description: "running pod not ready",
podStatus: "Running",
expectedErrCode: proto.StatusCode_STATUSCHECK_STANDALONE_PODS_PENDING,
expectedMessage: "pods not ready: [test-pod]",
},
{
description: "failed pod",
podStatus: "Failed",
expectedErrCode: proto.StatusCode_STATUSCHECK_UNKNOWN,
expectedMessage: "pod test-pod failed",
},
{
description: "pending pod",
podStatus: "Pending",
expectedErrCode: proto.StatusCode_STATUSCHECK_STANDALONE_PODS_PENDING,
expectedMessage: "pods not ready: [test-pod]",
},
{
description: "succeeded pod",
podStatus: "Succeeded",
expectedErrCode: proto.StatusCode_STATUSCHECK_SUCCESS,
expectedMessage: "",
},
{
description: "unknown status pod",
podStatus: "Unknown",
expectedErrCode: proto.StatusCode_STATUSCHECK_STANDALONE_PODS_PENDING,
expectedMessage: "pods not ready: [test-pod]",
},
}

for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
r := NewResource("test-standalone-pods", ResourceTypes.StandalonePods, ns, 42, false)
r.resources = map[string]validator.Resource{}
r.resources["test-pod"] = validator.NewResource(ns, "pod", "test-pod", validator.Status(test.podStatus), nil, nil)
r.CheckStatus(context.Background(), &statusConfig{})
t.CheckDeepEqual(r.status.ae.GetMessage(), test.expectedMessage)
t.CheckDeepEqual(r.status.ae.GetErrCode(), test.expectedErrCode)
})
}
}

func TestParseKubectlError(t *testing.T) {
tests := []struct {
description string
Expand Down

0 comments on commit 0778a47

Please sign in to comment.