From 97f9d625a987a6182d5c7b0e0f7722bb9ae8f4fa Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Tue, 6 Dec 2022 10:17:55 -0700 Subject: [PATCH] New system tests for conflicting options ...make sure podman rejects being called with incompatible options Replaces: https://github.com/containers/podman/pull/16813 Which is stuck in CI and Ed is on break. Signed-off-by: Ed Santiago Signed-off-by: Daniel J Walsh --- cmd/podman/containers/cleanup.go | 4 +-- test/system/620-option-conflicts.bats | 50 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 test/system/620-option-conflicts.bats diff --git a/cmd/podman/containers/cleanup.go b/cmd/podman/containers/cleanup.go index 6abc5df19b..7f619a4913 100644 --- a/cmd/podman/containers/cleanup.go +++ b/cmd/podman/containers/cleanup.go @@ -65,11 +65,11 @@ func cleanup(cmd *cobra.Command, args []string) error { if cleanupOptions.Exec != "" { switch { case cleanupOptions.All: - return errors.New("exec and all options conflict") + return errors.New("--all and --exec cannot be set together") case len(args) > 1: return errors.New("cannot use exec option when more than one container is given") case cleanupOptions.RemoveImage: - return errors.New("exec and rmi options conflict") + return errors.New("--exec and --rmi cannot be set together") } } diff --git a/test/system/620-option-conflicts.bats b/test/system/620-option-conflicts.bats new file mode 100644 index 0000000000..26c5d05d74 --- /dev/null +++ b/test/system/620-option-conflicts.bats @@ -0,0 +1,50 @@ +#!/usr/bin/env bats -*- bats -*- +# +# options that cannot be set together +# + +load helpers + + +@test "options that cannot be set together" { + skip_if_remote "not much point testing remote, and container-cleanup fails anyway" + + tests=" +create,run | --cpu-period=1 | --cpus=2 | $IMAGE +create,run | --cpu-quota=1 | --cpus=2 | $IMAGE +create,run | --no-hosts | --add-host=foo:1.1.1.1 | $IMAGE +create,run | --userns=bar | --pod=foo | $IMAGE +container cleanup | --all | --exec=foo +container cleanup | --exec=foo | --rmi | foo +" + + # FIXME: parse_table is what does all the work, giving us test cases. + while read subcommands opt1 opt2 args; do + opt1_name=${opt1%=*} + opt2_name=${opt2%=*} + + readarray -d, -t subcommand_list <<<$subcommands + for subcommand in "${subcommand_list[@]}"; do + run_podman 125 $subcommand $opt1 $opt2 $args + is "$output" "Error: $opt1_name and $opt2_name cannot be set together" \ + "podman $subcommand $opt1 $opt2" + + # Reverse order + run_podman 125 $subcommand $opt2 $opt1 $args + is "$output" "Error: $opt1_name and $opt2_name cannot be set together" \ + "podman $subcommand $opt2 $opt1" + done + done < <(parse_table "$tests") + + # Different error message; cannot be tested with the other ones above + for opt in arch os; do + for cmd in create pull; do + run_podman 125 $cmd --platform=foo --$opt=bar sdfsdf + is "$output" "Error: --platform option can not be specified with --arch or --os" \ + "podman $cmd --platform + --$opt" + done + done +} + + +# vim: filetype=sh