Skip to content

Commit

Permalink
test/e2e : updated assessment_runner.go
Browse files Browse the repository at this point in the history
Added code to handle the pod fail scenario by cross checking the error message we pass in .WithFailReason(reason string)

Fixes: #1760

Signed-off-by: Adapa Chathurya <[email protected]>
  • Loading branch information
chathuryaadapa committed Mar 28, 2024
1 parent 93ae704 commit 075a40e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/cloud-api-adaptor/test/e2e/assessment_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package e2e
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -78,6 +79,7 @@ type TestCase struct {
deletionWithin time.Duration
testInstanceTypes InstanceValidatorFunctions
isNydusSnapshotter bool
FailReason string
}

func (tc *TestCase) WithConfigMap(configMap *v1.ConfigMap) *TestCase {
Expand Down Expand Up @@ -170,6 +172,11 @@ func (tc *TestCase) WithNydusSnapshotter() *TestCase {
return tc
}

func (tc *TestCase) WithFailReason(reason string) *TestCase {
tc.FailReason = reason
return tc
}

func (tc *TestCase) Run() {
testCaseFeature := features.New(fmt.Sprintf("%s test", tc.testName)).
WithSetup("Create testworkload", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
Expand Down Expand Up @@ -416,6 +423,38 @@ func (tc *TestCase) Run() {
tc.assert.HasPodVM(t, tc.pod.Name)
}

if tc.podState != v1.PodRunning {
profile, error := tc.assert.GetInstanceType(t, tc.pod.Name)
if error != nil {
if error.Error() == "Failed to Create PodVM Instance" {
_, err := PodEventExtractor(ctx, client, *tc.pod)
if err != nil {
t.Fatal(err)
}
} else {
t.Fatal(error)
}
} else if profile != "" {
fmt.Printf("PodVM Created with Instance Type %v", profile)
if tc.FailReason != "" {
jsonData, err := json.Marshal(tc.pod.Status)
if err != nil {
fmt.Println("Error marshaling pod.Status to JSON: ", err.Error())
} else {
t.Logf("Current Pod State: %v", string(jsonData))
}
if strings.Contains(string(jsonData), tc.FailReason) {
log.Infof("failed due to expected reason %s", tc.FailReason)
} else {
t.Fatal(err)
}
} else {
log.Infof("Pod Failed If you want to cross check please give .WithFailReason(error string)")
}
tc.assert.HasPodVM(t, tc.pod.Name)
}
}

if tc.isNydusSnapshotter {
nodeName, err := GetNodeNameFromPod(ctx, client, *tc.pod)
if err != nil {
Expand Down

0 comments on commit 075a40e

Please sign in to comment.