2020-09-24 19:56:59 +08:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/containers/common/pkg/completion"
|
|
|
|
"github.com/spf13/pflag"
|
|
|
|
)
|
|
|
|
|
|
|
|
func testFlagCompletion(t *testing.T, flags pflag.FlagSet, flagCompletions completion.FlagCompletions) {
|
|
|
|
// lookup if for each flag a flag completion function exists
|
|
|
|
flags.VisitAll(func(f *pflag.Flag) {
|
|
|
|
// skip hidden, deprecated and boolean flags
|
|
|
|
if f.Hidden || len(f.Deprecated) > 0 || f.Value.Type() == "bool" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if _, ok := flagCompletions[f.Name]; !ok {
|
|
|
|
t.Errorf("Flag %q has no shell completion function set.", f.Name)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// make sure no unnecessary flag completion functions are defined
|
|
|
|
for name := range flagCompletions {
|
|
|
|
if flag := flags.Lookup(name); flag == nil {
|
bud: teach --platform to take a list
Add a pkg/parse.PlatformsFromOptions() which understands a "variant"
value as an optional third value in an OS/ARCH[/VARIANT] argument value,
which accepts a comma-separated list of them, and which returns a list
of platforms.
Teach "from" and "pull" about the --platform option and add integration
tests for them, warning if --platform was given multiple values.
Add a define.BuildOptions.JobSemaphore which an imagebuildah executor
will use in preference to one that it might allocate for itself.
In main(), allocate a JobSemaphore if the number of jobs is not 0 (which
we treat as "unlimited", and continue to allow executors to do).
In addManifest(), take a lock on the manifest list's image ID so that we
don't overwrite changes that another thread might be making while we're
attempting to make changes to it. In main(), create an empty list if
the list doesn't already exist before we start down this path, so that
we don't get two threads trying to create that manifest list at the same
time later on. Two processes could still try to create the same list
twice, but it's an incremental improvement.
Finally, if we've been given multiple platforms to build for, run their
builds concurrently and gather up their results.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-06-22 22:52:49 +08:00
|
|
|
t.Errorf("Flag %q does not exist but has a shell completion function set.", name)
|
2020-09-24 19:56:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUserNsFlagsCompletion(t *testing.T) {
|
|
|
|
flags := GetUserNSFlags(&UserNSResults{})
|
|
|
|
flagCompletions := GetUserNSFlagsCompletions()
|
|
|
|
testFlagCompletion(t, flags, flagCompletions)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNameSpaceFlagsCompletion(t *testing.T) {
|
|
|
|
flags := GetNameSpaceFlags(&NameSpaceResults{})
|
|
|
|
flagCompletions := GetNameSpaceFlagsCompletions()
|
|
|
|
testFlagCompletion(t, flags, flagCompletions)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBudFlagsCompletion(t *testing.T) {
|
|
|
|
flags := GetBudFlags(&BudResults{})
|
|
|
|
flagCompletions := GetBudFlagsCompletions()
|
|
|
|
testFlagCompletion(t, flags, flagCompletions)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFromAndBudFlagsCompletions(t *testing.T) {
|
|
|
|
flags, err := GetFromAndBudFlags(&FromAndBudResults{}, &UserNSResults{}, &NameSpaceResults{})
|
|
|
|
if err != nil {
|
2021-08-25 02:03:02 +08:00
|
|
|
t.Error("Could load the from and build flags.")
|
2020-09-24 19:56:59 +08:00
|
|
|
}
|
|
|
|
flagCompletions := GetFromAndBudFlagsCompletions()
|
|
|
|
testFlagCompletion(t, flags, flagCompletions)
|
|
|
|
}
|