mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-22 18:37:15 +00:00
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:
@@ -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())
|
||||
|
@@ -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())
|
||||
}
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user