Skip to content

Commit

Permalink
oci/auth: Add test to check for non-test flags
Browse files Browse the repository at this point in the history
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 <darkowlzz@protonmail.com>
  • Loading branch information
darkowlzz committed Sep 6, 2023
1 parent f01d884 commit e6669d8
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions oci/auth/flag_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit e6669d8

Please sign in to comment.