System tests: help messages: check required-arg

If a usage message is of the form '... [flags] ARGNAME',
where ARGNAME is all-caps and not in brackets, it must
be a required argument. Try running podman subcommand
without ARGNAME, and make sure that podman bails out
with an informative message. (Since this message is
freeform in each subcommand, not Cobra-generated,
we have a lot of possible variations to check for).

Fix podman login/logout Use messages to indicate that
REGISTRY is now optional (as of #5233).

This test has actually been in place for over a year but
due to a typo on my part -- a missing space -- it was
not being run. "For want of a space, much testing was lost".

Signed-off-by: Ed Santiago <santiago@redhat.com>
This commit is contained in:
Ed Santiago
2020-04-29 10:03:12 -06:00
committed by baude
parent c31bf2e976
commit 91a42fefcb
3 changed files with 19 additions and 6 deletions

View File

@ -19,7 +19,7 @@ type loginOptionsWrapper struct {
var ( var (
loginOptions = loginOptionsWrapper{} loginOptions = loginOptionsWrapper{}
loginCommand = &cobra.Command{ loginCommand = &cobra.Command{
Use: "login [flags] REGISTRY", Use: "login [flags] [REGISTRY]",
Short: "Login to a container registry", Short: "Login to a container registry",
Long: "Login to a container registry on a specified server.", Long: "Login to a container registry on a specified server.",
RunE: login, RunE: login,

View File

@ -14,7 +14,7 @@ import (
var ( var (
logoutOptions = auth.LogoutOptions{} logoutOptions = auth.LogoutOptions{}
logoutCommand = &cobra.Command{ logoutCommand = &cobra.Command{
Use: "logout [flags] REGISTRY", Use: "logout [flags] [REGISTRY]",
Short: "Logout of a container registry", Short: "Logout of a container registry",
Long: "Remove the cached username and password for the registry.", Long: "Remove the cached username and password for the registry.",
RunE: logout, RunE: logout,

View File

@ -55,11 +55,24 @@ function check_help() {
# If usage has required arguments, try running without them # If usage has required arguments, try running without them
if expr "$usage" : '.*\[flags\] [A-Z]' >/dev/null; then if expr "$usage" : '.*\[flags\] [A-Z]' >/dev/null; then
if [ "$cmd" != "stats"]; then # Exceptions: these commands don't work rootless
dprint "podman $@ $cmd (without required args)" if is_rootless; then
run_podman 125 "$@" $cmd # "pause is not supported for rootless containers"
is "$output" "Error:" if [ "$cmd" = "pause" -o "$cmd" = "unpause" ]; then
continue
fi
# "network rm" too
if [ "$@" = "network" -a "$cmd" = "rm" ]; then
continue
fi
fi fi
# The </dev/null protects us from 'podman login' which will
# try to read username/password from stdin.
dprint "podman $@ $cmd (without required args)"
run_podman 125 "$@" $cmd </dev/null
is "$output" "Error:.* \(require\|specif\|must\|provide\|need\|choose\)" \
"'podman $@ $cmd' without required arg"
fi fi
count=$(expr $count + 1) count=$(expr $count + 1)