Skip to content

Commit

Permalink
chore: aggregate test steps into one
Browse files Browse the repository at this point in the history
Signed-off-by: Kumar Mallikarjuna <[email protected]>
  • Loading branch information
kumar-mallikarjuna committed Jan 7, 2025
1 parent 8d7cdf0 commit dd2131a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
20 changes: 8 additions & 12 deletions pkg/test/expression_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,22 @@ func TestAssertExpressions(t *testing.T) {
files, err := os.ReadDir(dirName)
assert.NoError(t, err)

for i := 0; i < len(files)-1; i++ {
fName := fmt.Sprintf("%s/%s", dirName, files[i].Name())
step := buildTestStep(t, testenv)
assert.NoError(t, step.LoadYAML(fName))
assert.NoError(t, errors.Join(errors.Join(step.Run(t, testNamespace)...)))
}

step := buildTestStep(t, testenv)
for _, file := range files {
fName := fmt.Sprintf("%s/%s", dirName, file.Name())
if err = step.LoadYAML(fName); err != nil {
break
}
}

fName := fmt.Sprintf("%s/%s", dirName, files[len(files)-1].Name())

err = step.LoadYAML(fName)
if !tc.expectLoadFailure {
assert.NoError(t, err)
} else {
} else if tc.expectLoadFailure {
assert.ErrorContains(t, err, tc.expectedErrorMessage)
return
}

err = errors.Join(step.Run(t, testNamespace)...)
err = errors.Join(errors.Join(step.Run(t, testNamespace)...))
if !tc.expectRunFailure {
assert.NoError(t, err)
} else {
Expand Down
7 changes: 7 additions & 0 deletions pkg/test/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (s *Step) Create(test *testing.T, namespace string) []error {

errors := []error{}

fmt.Println("HEREA1", len(s.Apply))
for _, obj := range s.Apply {
_, _, err := kubernetes.Namespaced(dClient, obj, namespace)
if err != nil {
Expand Down Expand Up @@ -225,7 +226,10 @@ func (s *Step) Create(test *testing.T, namespace string) []error {
}
s.Logger.Log(kubernetes.ResourceID(obj), action)
}

fmt.Println("HEREA", obj.GetNamespace(), obj.GetName())
}
fmt.Println("HEREB", errors)

return errors
}
Expand Down Expand Up @@ -429,6 +433,7 @@ func (s *Step) CheckAssertExpressions(namespace string) []error {
}
namespacedName, referencedResource := resourceRef.BuildResourceReference()
if err := client.Get(context.TODO(), namespacedName, referencedResource); err != nil {
fmt.Println("HEREB", err)
return []error{fmt.Errorf("failed to get referenced resource '%v': %w", namespacedName, err)}
}

Expand Down Expand Up @@ -679,6 +684,8 @@ func (s *Step) populateObjectsByFileName(fileName string, objects []client.Objec
return fmt.Errorf("%s does not match file name regexp: %s", fileName, testStepRegex.String())
}

fmt.Println("HEREC", strings.ToLower(matches[1]))

switch fname := strings.ToLower(matches[1]); fname {
case "assert":
s.Asserts = append(s.Asserts, objects...)
Expand Down

0 comments on commit dd2131a

Please sign in to comment.