e2e: detect unexpected command line arguments

Invalid flags are detected by flag parsing, but optional arguments are just
passed through to the E2E suites. None of them support any, so rejecting them
with an error message is useful because it helps catch typos (like a missing
hyphen before a flag).
This commit is contained in:
Patrick Ohly 2023-06-19 12:46:21 +02:00
parent a9a7a3730e
commit 932d0337b8
3 changed files with 14 additions and 0 deletions

View File

@ -92,6 +92,11 @@ func TestMain(m *testing.M) {
os.Exit(0)
}
if flag.CommandLine.NArg() > 0 {
fmt.Fprintf(os.Stderr, "unknown additional command line arguments: %s", flag.CommandLine.Args())
os.Exit(1)
}
// Enable embedded FS file lookup as fallback
testfiles.AddFileSource(e2etestingmanifests.GetE2ETestingManifestsFS())
testfiles.AddFileSource(testfixtures.GetTestFixturesFS())

View File

@ -18,6 +18,7 @@ package kubeadm
import (
"flag"
"fmt"
"os"
"testing"
@ -42,6 +43,10 @@ func TestMain(m *testing.M) {
framework.RegisterClusterFlags(flag.CommandLine)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
if pflag.CommandLine.NArg() > 0 {
fmt.Fprintf(os.Stderr, "unknown additional command line arguments: %s", pflag.CommandLine.Args())
os.Exit(1)
}
framework.AfterReadingAllFlags(&framework.TestContext)
os.Exit(m.Run())
}

View File

@ -130,6 +130,10 @@ func TestMain(m *testing.M) {
rand.Seed(time.Now().UnixNano())
pflag.Parse()
if pflag.CommandLine.NArg() > 0 {
fmt.Fprintf(os.Stderr, "unknown additional command line arguments: %s", pflag.CommandLine.Args())
os.Exit(1)
}
framework.AfterReadingAllFlags(&framework.TestContext)
if err := e2eskipper.InitFeatureGates(utilfeature.DefaultFeatureGate, featureGates); err != nil {
fmt.Fprintf(os.Stderr, "ERROR: initialize feature gates: %v", err)