Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

[Enhancement] Easy checking of CLI output #35

Merged
merged 24 commits into from
Sep 16, 2023
Merged

Conversation

shubham-cmyk
Copy link
Member

What this PR does / why we need it:

This PR would add an declarative way to check the output of the structs.

This types of command could be used now :

apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: echo "Hello World"
  output:
    stdout:
      contains: "Hello World"
    stderr:
      contains: "Hello World"

Fixes #22

@eddycharly
Copy link
Member

@shubham-cmyk you have linter issues

@shubham-cmyk
Copy link
Member Author

@eddycharly

I am trying to fix this but this is not fixing :

gofmt -w /pkg/test/utils/kubernetes.go

@eddycharly
Copy link
Member

eddycharly commented Sep 14, 2023

How about something like:

apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: echo "Hello World"
  output:
    stdout:
      expected: "Hello ?*"
      match: Wildcard
    stderr:
      expected: "Hello World"
      match: Equals

@eddycharly
Copy link
Member

Looks like it would be more extensible 🤷

@shubham-cmyk
Copy link
Member Author

apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: echo "Hello World"
  output:
    stdout:
      expected: "Hello ?*"
      match: Wildcard
    stderr:
      expected: "Hello World"
      match: Equals

Okay, the Match could be Equal ( strict ) and contains ( just string contains check ) a wildcard (wildcard check could be passed) .....

Or we should keep match to equals and wildcard

@eddycharly
Copy link
Member

I think Equals and Wildcard are enough to cover 99% cases.
We might need Contains in very specific situations though and it shouldn't rely on wildcards (when the expected output contains * or ? but we don't want to treat them as wildcard patterns...)

@eddycharly
Copy link
Member

Something like this will not work well:

apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: echo "Hello World"
  output:
    stdout:
      expected: "How are you today ?"
      match: Wildcard

@shubham-cmyk
Copy link
Member Author

So let's push contains it would be good 👍

@eddycharly
Copy link
Member

So let's push contains it would be good 👍

Ok, fine.

@chipzoller
Copy link

Any schema changes just be sure that the initial post in this PR has a full and complete description of what's available.

Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
@shubham-cmyk
Copy link
Member Author

shubham-cmyk commented Sep 14, 2023

These below structs are added. ( edited )


type CommandOutput struct {
	Stdout ExpectedOutput `json:"stdout"`
	Stderr ExpectedOutput `json:"stderr"`
}

type ExpectedOutput struct {
	MatchType string `json:"match"`
	ExpectedValue string `json:"expected"`
}

Now we could have something like :

For only wild-card match.

apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: echo "Hello World"
  output:
    stdout:
      match: wildcard
      expected:  " any pattern "

Strictly the stdout should be equal what I define.

apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: echo "Hello World"
  output:
    stdout:
      match: equals
      expected: "Hello World"

Check whether the the stdout contains the "hello"

apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: echo "Hello World"
  output:
    stdout:
      match: contains
      expected:  "Hello"

@eddycharly
Copy link
Member

@shubham-cmyk the changes here do not reflect this:

  output:
    stdout:
      expected: "How are you today ?"
      match: Wildcard

Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
@shubham-cmyk
Copy link
Member Author

@eddycharly

tools.go Show resolved Hide resolved
@eddycharly
Copy link
Member

It would be nice to cover this with tests too 🙏

Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
@shubham-cmyk
Copy link
Member Author

It would be nice to cover this with tests too 🙏

Added unit_test to cover this function.

Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
@eddycharly
Copy link
Member

@shubham-cmyk please raise an error if background is true and output checks are present

Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
@shubham-cmyk
Copy link
Member Author

@shubham-cmyk please raise an error if background is true and output checks are present

Done

Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
eddycharly and others added 2 commits September 16, 2023 22:19
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
@eddycharly eddycharly merged commit 6d26d82 into kyverno:main Sep 16, 2023
5 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] Easy checking of CLI output
3 participants