Skip to content

Commit

Permalink
chore: make linter happy and initialize Programs only if assertions a…
Browse files Browse the repository at this point in the history
…re present

Signed-off-by: Kumar Mallikarjuna <[email protected]>
  • Loading branch information
kumar-mallikarjuna committed Dec 3, 2024
1 parent a7e5287 commit a85752a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
11 changes: 6 additions & 5 deletions pkg/apis/testharness/v1beta1/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ func (t *TestResourceRef) BuildResourceReference() (namespacedName types.Namespa

func (t *TestResourceRef) Validate() error {
apiVersionSplit := strings.Split(t.APIVersion, "/")
if t.APIVersion == "" || (len(apiVersionSplit) != 1 && len(apiVersionSplit) != 2) {
switch {
case t.APIVersion == "" || (len(apiVersionSplit) != 1 && len(apiVersionSplit) != 2):
return fmt.Errorf("apiVersion '%v' not of the format (<group>/)<version>", t.APIVersion)
} else if t.Kind == "" {
case t.Kind == "":
return errors.New("kind not specified")
} else if t.Namespace == "" {
case t.Namespace == "":
return errors.New("namespace not specified")
} else if t.Name == "" {
case t.Name == "":
return errors.New("name not specified")
} else if t.Ref == "" {
case t.Ref == "":
return errors.New("ref not specified")
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/test/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func (s *Step) CheckAssertExpressions(
return []error{err}
}

return testutils.RunAssertExpressions(ctx, s.Logger, client, s.Programs, resourceRefs, assertAny, assertAll)
return testutils.RunAssertExpressions(ctx, client, s.Programs, resourceRefs, assertAny, assertAll)
}

// Check checks if the resources defined in Asserts and Errors are in the correct state.
Expand Down Expand Up @@ -533,8 +533,6 @@ func (s *Step) String() string {
// if seen, mark a test immediately failed.
// - All other YAML files are considered resources to create.
func (s *Step) LoadYAML(file string) error {
s.Programs = make(map[string]cel.Program)

skipFile, objects, err := s.loadOrSkipFile(file)
if skipFile || err != nil {
return err
Expand Down Expand Up @@ -574,6 +572,10 @@ func (s *Step) LoadYAML(file string) error {
return fmt.Errorf("failed to load TestAssert object from %s: %w", file, err)
}

if len(assertions) > 0 {
s.Programs = make(map[string]cel.Program)
}

for _, assertion := range assertions {
if prg, err := assertion.BuildProgram(env); err != nil {
errs = append(errs, err)
Expand Down
1 change: 0 additions & 1 deletion pkg/test/utils/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,6 @@ func RunAssertCommands(ctx context.Context, logger Logger, namespace string, com
// RunAssertExpressions evaluates a set of CEL expressions specified as AnyAllExpressions
func RunAssertExpressions(
ctx context.Context,
logger Logger,
cl client.Client,
programs map[string]cel.Program,
resourceRefs []harness.TestResourceRef,
Expand Down

0 comments on commit a85752a

Please sign in to comment.