Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KEP-0009] feat: add expression based assertions #576

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bd77825
[KEP-0009] feat: add expression based assertions
kumar-mallikarjuna Nov 22, 2024
68c60e3
chore: rename Id->Ref and make linter happy
kumar-mallikarjuna Nov 27, 2024
9a94a6b
chore: add validation for resourceRefs
kumar-mallikarjuna Nov 27, 2024
38819ef
chore: make assertion syntax consistent with the KEP
kumar-mallikarjuna Nov 27, 2024
3a6b02e
refactor: rename Validate method for `TestResourceRef`
kumar-mallikarjuna Nov 27, 2024
bd362f2
chore: pre-build environment and program for expressions
kumar-mallikarjuna Dec 3, 2024
14ad7a8
chore: make linter happy and initialize Programs only if assertions a…
kumar-mallikarjuna Dec 3, 2024
6df2e32
chore: incorporate review comments
kumar-mallikarjuna Dec 3, 2024
aa6cb65
chore: move RunAssertExpressions() to pkg/expressions
kumar-mallikarjuna Dec 3, 2024
832bf9e
refactor: move CEL program loading to a dedicated function
kumar-mallikarjuna Dec 3, 2024
e32b53e
refactor: move program-loading to Step out of LoadPrograms()
kumar-mallikarjuna Dec 3, 2024
3223ada
chore: add tests for `TestResourceRef`
kumar-mallikarjuna Dec 4, 2024
f08a27e
fix: correct evaluation for `assertAll`
kumar-mallikarjuna Dec 4, 2024
7cb27fc
chore: add integration tests for expressions
kumar-mallikarjuna Dec 4, 2024
3fcf018
chore: make linter happy
kumar-mallikarjuna Dec 4, 2024
c6c3e8a
chore: incorporate review comments
kumar-mallikarjuna Dec 14, 2024
51e3deb
fix: change array reference for all-asserts
kumar-mallikarjuna Dec 14, 2024
32330e9
chore: change signature for `CheckAssertExpressions()`
kumar-mallikarjuna Dec 17, 2024
5e252f5
chore: use envtest in `expression_integration_test.go`
kumar-mallikarjuna Dec 17, 2024
56c1779
fix: remove redundant definitions for integration test tools
kumar-mallikarjuna Dec 17, 2024
2c58b63
chore: use testenv in expression_integration_test.go
kumar-mallikarjuna Dec 18, 2024
aa2fa55
fix: run target expressions test within a Kuttl owned ephemeral names…
kumar-mallikarjuna Dec 19, 2024
9e77060
chore: remove redundant file and update go.mod
kumar-mallikarjuna Dec 19, 2024
f824fb9
chore: incorporate review comments
kumar-mallikarjuna Dec 19, 2024
965b7eb
chore: update error messages
kumar-mallikarjuna Dec 19, 2024
5173e6c
chore: update error message
kumar-mallikarjuna Dec 19, 2024
4f358b0
chore: incorporate review comments
kumar-mallikarjuna Jan 3, 2025
60b818d
fix: update context creation
kumar-mallikarjuna Jan 3, 2025
dd85a98
chore: aggregate test steps into one
kumar-mallikarjuna Jan 7, 2025
d510656
chore: remove debug statements
kumar-mallikarjuna Jan 8, 2025
7c164ba
chore(tests): remove prefixes for expression integration test steps
kumar-mallikarjuna Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions pkg/test/expression_integration_test.go
porridge marked this conversation as resolved.
Show resolved Hide resolved
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))
kumar-mallikarjuna marked this conversation as resolved.
Show resolved Hide resolved
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
Loading