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

e2e: redefine ExitWithError() to require exit code #22270

Merged

Conversation

edsantiago
Copy link
Member

@edsantiago edsantiago commented Apr 5, 2024

...and an optional error-message string, to be checked against stderr.

This is a starting point and baby-steps progress toward #18188. There are 249 ExitWithError() checks in test/e2e. It will take weeks to fix them all. This commit enables new functionality:

Expect(ExitWithError(125, "expected substring"))

...while also allowing the current empty-args form. Once all 249 empty-args uses are modernized, the matcher code will be cleaned up.

I expect it will take several months of light effort to get all e2e tests transitioned to the new form. I am choosing to do so in pieces, for (relative) ease of review. This PR:

  1. makes the initial changes described above; and
  2. updates a small subset of e2e _test.go files such that:
    a) ExitWithError() is given an exit code and error string; and
    b) Exit(Nonzero) is changed to ExitWithError(Nonzero, "string") (when possible)
None

@openshift-ci openshift-ci bot added release-note-none do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Apr 5, 2024
@edsantiago edsantiago marked this pull request as draft April 5, 2024 01:14
Copy link
Contributor

openshift-ci bot commented Apr 5, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: edsantiago

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 5, 2024
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think conceptionally this is fine. We can then extend it to check that stderr is always checked, i.e. if no message is given to ExitWithError() then stderr must be empty which is needed for command like podman run alpine false

As far as remote vs local goes, we can always do
IsRemote{ matcher1 } else { matcher2 } where it is actually required.

@@ -35,7 +35,7 @@ var _ = Describe("Podman checkpoint", func() {
checkpointImage := "foobar-checkpoint"
session := podmanTest.Podman([]string{"container", "checkpoint", "--create-image", checkpointImage, "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, "no container with name or ID \"foobar\" found: no such container"))
Expect(session.ErrorToString()).To(ContainSubstring("no container with name or ID \"foobar\" found"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the line already checks the stderr

Comment on lines +31 to +32
// FIXME: once all ExitWithError()s have been migrated to new form,
// change interface to (int, ...string)
Copy link
Member

@Luap99 Luap99 Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 that is important for proper type hints and compile time enforcement

@mheon
Copy link
Member

mheon commented Apr 8, 2024

I like this. LGTM so far.

@edsantiago
Copy link
Member Author

Thanks. I'm slowly replacing ExitWithError instances in my work branch and am debating submitting what I've got (for ease of review) or continuing with a monster PR. Any preferences?

@edsantiago edsantiago force-pushed the redefine-ExitWithError branch 5 times, most recently from 46e3908 to a43c29a Compare April 9, 2024 15:07
@edsantiago edsantiago changed the title WIP: e2e: redefine ExitWithError() to require exit code e2e: redefine ExitWithError() to require exit code Apr 9, 2024
@edsantiago edsantiago force-pushed the redefine-ExitWithError branch from a43c29a to 85f145f Compare April 9, 2024 16:17
Copy link
Member Author

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pointing out a couple of instances demonstrating the value of this.

This has grown to just about what I think is reasonable for review. Maybe a little over (sorry). I will pause here, accept feedback, then proceed with the process once this merges.

Comment on lines 23 to 20
It("podman exec without command", func() {
session := podmanTest.Podman([]string{"exec", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(ExitWithError(125, "no container with name or ID \"foobar\" found: no such container"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why I'm "wasting" my time on this seemingly-trivial exercise.

This entire test was pointless. I'm sure the author wanted it to fail with "must provide a non-empty command", but in reality it was failing with "container foobar does not exist and I'm not even going to bother checking the rest of the args".

I added this test (as intended) as a piggyback onto simple command below.

Comment on lines -21 to -24
It("podman generate systemd bad restart policy", func() {
session := podmanTest.Podman([]string{"generate", "systemd", "--restart-policy", "never", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another completely pointless test: this was failing with "I'm gonna check the container name first, before even checking options, and foobar doesn't exist, so this test doesn't even test what you think it's testing". Fortunately this was a dup, and the "bogus" test below was already testing this functionality.

@edsantiago edsantiago removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 9, 2024
@edsantiago edsantiago marked this pull request as ready for review April 9, 2024 17:35
})

It("podman generate systemd bad timeout value", func() {
session := podmanTest.Podman([]string{"generate", "systemd", "--time", "-1", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
Expect(session).To(ExitWithError(125, "invalid argument \"-1\" for \"-t, --time\" flag: strconv.ParseUint: parsing \"-1\": invalid syntax"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hint, if you like to avoid all the quoting you can use backticks to create a "raw" string without any required escaping, i.e.

`invalid argument "-1" for "-t, --time" flag: strconv.ParseUint: parsing "-1": invalid syntax`

Not required of course but IMO makes it easer to read.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I prefer the backtick form too, but its use in our code base is rare. I'm in the process of fixing these (only in my changes) and will repush.

test/e2e/exec_test.go Show resolved Hide resolved
@@ -74,7 +73,7 @@ var _ = Describe("Podman create with --ip flag", func() {
// test1 container is running with the given IP.
result = podmanTest.Podman([]string{"start", "-a", "test2"})
result.WaitWithDefaultTimeout()
Expect(result).To(ExitWithError())
Expect(result).To(ExitWithError(125))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK we dropped CNI tests so could you just simply this block below and only match the netavark message?

@Luap99
Copy link
Member

Luap99 commented Apr 10, 2024

overall LGTM, very good improvements

@edsantiago edsantiago force-pushed the redefine-ExitWithError branch from 85f145f to 1b933a1 Compare April 10, 2024 12:08
} else if podmanTest.NetworkBackend == Netavark {
Expect(result.ErrorToString()).To(ContainSubstring("requested ip address %s is already allocated", ip))
}
Expect(result).To(ExitWithError(125, " is already allocated"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Luap99 is this what you meant?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes although if we do not want to loose the ip I suggest using

fmt.Sprintf("requested ip address %s is already allocated", ip)

to create the proper error string
But I do not think it is super important one way or another so I am fine with the current version as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I think ExitWithError(xxx, fmt.Sprintf())` looks clunky, but tighter testing is better testing. So done.

ContainSubstring() is kind of nice in how it takes varargs. I think that's nicely readable, but I just didn't want to complicate this PR even more by adding that to ExitWithError(). Would that be worth pursuing once this exercise is done and I tighten up the ExitWithError() signature?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContainSubstring() is kind of nice in how it takes varargs. I think that's nicely readable, but I just didn't want to complicate this PR even more by adding that to ExitWithError(). Would that be worth pursuing once this exercise is done and I tighten up the ExitWithError() signature?

Yes I think that would be valuable but definitely not worth to block this work over it.

...and an optional error-message string, to be checked
against stderr.

This is a starting point and baby-steps progress toward containers#18188.
There are 249 ExitWithError() checks in test/e2e. It will take
weeks to fix them all. This commit enables new functionality:

    Expect(ExitWithError(125, "expected substring"))

...while also allowing the current empty-args form. Once
all 249 empty-args uses are modernized, the matcher code
will be cleaned up.

I expect it will take several months of light effort to get
all e2e tests transitioned to the new form. I am choosing to
do so in pieces, for (relative) ease of review. This PR:

  1) makes the initial changes described above; and
  2) updates a small subset of e2e _test.go files such that:
     a) ExitWithError() is given an exit code and error string; and
     b) Exit(Nonzero) is changed to ExitWithError(Nonzero, "string")
        (when possible)

Signed-off-by: Ed Santiago <[email protected]>
@edsantiago edsantiago force-pushed the redefine-ExitWithError branch from 1b933a1 to 2d91598 Compare April 10, 2024 12:36
@mheon
Copy link
Member

mheon commented Apr 10, 2024

LGTM

@Luap99
Copy link
Member

Luap99 commented Apr 10, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 10, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 17f36a3 into containers:main Apr 10, 2024
94 checks passed
@edsantiago edsantiago deleted the redefine-ExitWithError branch April 10, 2024 14:59
edsantiago added a commit to edsantiago/libpod that referenced this pull request May 8, 2024
Followup to containers#22270: wherever possible/practical, extend command
error checks to include explicit exit status codes and error strings.

This commit handles all remaining test/e2e/p*_test.go

Signed-off-by: Ed Santiago <[email protected]>
edsantiago added a commit to edsantiago/libpod that referenced this pull request May 13, 2024
Followup to containers#22270: wherever possible/practical, extend command
error checks to include explicit exit status codes and error strings.

This commit handles a subset of test/e2e/run_xxx_test.go

Signed-off-by: Ed Santiago <[email protected]>
edsantiago added a commit to edsantiago/libpod that referenced this pull request May 13, 2024
Followup to containers#22270: wherever possible/practical, extend command
error checks to include explicit exit status codes and error strings.

This commit handles test/e2e/s*_test.go

Signed-off-by: Ed Santiago <[email protected]>
edsantiago added a commit to edsantiago/libpod that referenced this pull request May 13, 2024
Followup to containers#22270: wherever possible/practical, extend command
error checks to include explicit exit status codes and error strings.

This commit handles all remaining test/e2e/r*_test.go

Signed-off-by: Ed Santiago <[email protected]>
edsantiago added a commit to edsantiago/libpod that referenced this pull request May 13, 2024
Followup to containers#22270: wherever possible/practical, extend command
error checks to include explicit exit status codes and error strings.

This commit handles only one file, test/e2e/rmi_test.go , because
my changes are significant enough to merit individual review.

Signed-off-by: Ed Santiago <[email protected]>
edsantiago added a commit to edsantiago/libpod that referenced this pull request May 13, 2024
Final followup to containers#22270. That PR added a temporary convention
allowing a new form of ExitWithError(), one with an exit code
and stderr substring. In order to allow bite-size progress,
the old no-args form was still allowed. This PR removes
support for no-args ExitWithError().

This PR also adds one piece of new functionality: passing ""
(empty string) as the stderr arg means "expect exit code
but fail if there's anything at all in stderr".

Signed-off-by: Ed Santiago <[email protected]>
@stale-locking-app stale-locking-app bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Jul 10, 2024
@stale-locking-app stale-locking-app bot locked as resolved and limited conversation to collaborators Jul 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants