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

apiv2 tests: finally fix POST as originally intended #9686

Merged
merged 1 commit into from
Mar 11, 2021

Conversation

edsantiago
Copy link
Member

When I originally wrote this code I had no idea what POST
would look like so I did a sloppy job, deferring making it
usable. Now that we have some real-world examples in place,
I have a better understanding of what params look like and
how to make tests more readable/maintainable. (Deferring isn't
always bad: one of my early ideas was to separate params using
commas; that would've been a disaster because some JSON values,
such as arrays, include commas).

This commit implements a better way of dealing with POST:

  • The main concept is still 'key=value'
    • When value is a JSON object (dictionary, array), it
      can be quoted.
    • Multiple params are simply separated by spaces.
      The 3-digit HTTP code is a prominent, readable separator
      between POST params and expected results. The parsing
      code is a little uglier, but test developers need
      never see that. The important thing is that writing
      tests is now easier.
  • POST params can be empty (this removes the need for a
    useless '')

I snuck in one unrelated change: one of the newly-added
tests, .NetworkSettings, was failing when run rootless
(which is how I test on my setup). I made it conditional.

Signed-off-by: Ed Santiago [email protected]

When I originally wrote this code I had no idea what POST
would look like so I did a sloppy job, deferring making it
usable. Now that we have some real-world examples in place,
I have a better understanding of what params look like and
how to make tests more readable/maintainable. (Deferring isn't
always bad: one of my early ideas was to separate params using
commas; that would've been a disaster because some JSON values,
such as arrays, include commas).

This commit implements a better way of dealing with POST:

  * The main concept is still 'key=value'
    * When value is a JSON object (dictionary, array), it
      can be quoted.
    * Multiple params are simply separated by spaces.
      The 3-digit HTTP code is a prominent, readable separator
      between POST params and expected results. The parsing
      code is a little uglier, but test developers need
      never see that. The important thing is that writing
      tests is now easier.
  * POST params can be empty (this removes the need for a
    useless '')

I snuck in one unrelated change: one of the newly-added
tests, .NetworkSettings, was failing when run rootless
(which is how I test on my setup). I made it conditional.

Signed-off-by: Ed Santiago <[email protected]>
@openshift-ci-robot
Copy link
Collaborator

[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-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 10, 2021
@edsantiago
Copy link
Member Author

Review Suggestions: I realize this is a mess to review. If I may make a couple of suggestions:

  • Look at the first few ''-only (quote-only) changes. If you're happy with those, train your eye to ignore them because they're all the same and they're all mostly noise.
  • For the real changes, the ones with real params, ignore the old value (gobbledygook clutter) and just focus on the new value: is it readable? Is it correct?
  • Give a once-over to the parsing code in test-apiv2 but if you're not a bash person, just assume that if the tests pass, the code is good. (I know. That's never good advice).

Comment on lines -34 to +43
# Test compat API for Network Settings
# Test compat API for Network Settings (.Network is N/A when rootless)
network_expect=
if root; then
network_expect='.[0].NetworkSettings.Networks.podman.NetworkID=podman'
fi
t GET /containers/json?all=true 200 \
length=1 \
.[0].Id~[0-9a-f]\\{64\\} \
.[0].Image=$IMAGE \
.[0].NetworkSettings.Networks.podman.NetworkID=podman
$network_expect
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 the one non-param-related change, the one I snuck in. All it does is, if running rootless, skip the .NetworkSettings check but run the others.

t POST myentrypoint 200 ! no params
t POST myentrypoint id=$id 200 ! just one
t POST myentrypoint id=$id filter='{"foo":"bar"}' 200 ! two, with json
t POST myentrypoint name=$name badparam='["foo","bar"]' 500 ! etc...
Copy link
Member

Choose a reason for hiding this comment

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

Would foo="value with space" be counted as one argument?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, good question. I was careful to do arg processing the "correct" way, so yes, it should work, but I don't have any explicit tests for it. I think it might be time to add an internal test suite for that helper. Unfortunately, my sneak-in-some-work-time for today has run out! I'll get to that when I can. Thanks for pointing it out.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you, LGTM :)

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

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

LGTM
@containers/podman-maintainers PTAL

@rhatdan
Copy link
Member

rhatdan commented Mar 10, 2021

/lgtm
/hold

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 10, 2021
@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 10, 2021
@rhatdan
Copy link
Member

rhatdan commented Mar 10, 2021

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 10, 2021
@rhatdan rhatdan merged commit 81737b3 into containers:master Mar 11, 2021
@edsantiago edsantiago deleted the apiv2_jsonify branch March 13, 2021 21:28
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2023
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants