From e6669d82c8635a247b1034ee7d74e17229eeb5a7 Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 6 Sep 2023 16:01:36 +0000 Subject: [PATCH] oci/auth: Add test to check for non-test flags Add a black box test to import the auth package as a consumer of the package and make sure that no flags are injected. Being in a test, it ignores all the default test flags with "test." prefix. Signed-off-by: Sunny --- oci/auth/flag_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 oci/auth/flag_test.go diff --git a/oci/auth/flag_test.go b/oci/auth/flag_test.go new file mode 100644 index 00000000..229ba8f7 --- /dev/null +++ b/oci/auth/flag_test.go @@ -0,0 +1,36 @@ +/* +Copyright 2023 The Flux authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Make sure we never inject non-test flags when the auth packages are imported. +// Refer https://github.com/fluxcd/pkg/issues/645. +package auth_test + +import ( + "flag" + "strings" + "testing" + + _ "github.com/fluxcd/pkg/oci/auth/login" +) + +func TestNonTestFlagCheck(t *testing.T) { + flagCheck := func(f *flag.Flag) { + if !strings.HasPrefix(f.Name, "test.") { + t.Errorf("found non-test command line flag: %q", f.Name) + } + } + flag.VisitAll(flagCheck) +}