Skip to content

Commit

Permalink
tests/e2e: fix skipRootUserTests flag 🎏
Browse files Browse the repository at this point in the history
Before this fix, the flag doesn't set the variable as it might never
be parsed.

- mark the flag as boolean
- flag.parse in `TestMain` to make sure it is parsed

Signed-off-by: Vincent Demeester <[email protected]>
  • Loading branch information
vdemeester committed Mar 30, 2020
1 parent 0b3a8b1 commit 9b570aa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
6 changes: 6 additions & 0 deletions test/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ import (
)

var initMetrics sync.Once
var skipRootUserTests = false

func init() {
flag.BoolVar(&skipRootUserTests, "skipRootUserTests", false, "Skip tests that require root user")
}

func setup(t *testing.T, fn ...func(*testing.T, *clients, string)) (*clients, string) {
t.Helper()
Expand Down Expand Up @@ -146,6 +151,7 @@ func verifyServiceAccountExistence(t *testing.T, namespace string, kubeClient *k
// TestMain initializes anything global needed by the tests. Right now this is just log and metric
// setup since the log and metric libs we're using use global state :(
func TestMain(m *testing.M) {
flag.Parse()
c := m.Run()
fmt.Fprintf(os.Stderr, "Using kubeconfig at `%s` with cluster `%s`\n", knativetest.Flags.Kubeconfig, knativetest.Flags.Cluster)
os.Exit(c)
Expand Down
9 changes: 0 additions & 9 deletions test/kaniko_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ limitations under the License.
package test

import (
"flag"
"fmt"
"strings"
"testing"
Expand All @@ -44,14 +43,6 @@ const (
revision = "1c9d566ecd13535f93789595740f20932f655905"
)

var (
skipRootUserTests = "false"
)

func init() {
flag.StringVar(&skipRootUserTests, "skipRootUserTests", "false", "Skip tests that require root user")
}

// TestTaskRun is an integration test that will verify a TaskRun using kaniko
func TestKanikoTaskRun(t *testing.T) {
if skipRootUserTests == "true" {
Expand Down
6 changes: 6 additions & 0 deletions test/v1alpha1/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ import (
)

var initMetrics sync.Once
var skipRootUserTests = false

func init() {
flag.BoolVar(&skipRootUserTests, "skipRootUserTests", false, "Skip tests that require root user")
}

func setup(t *testing.T, fn ...func(*testing.T, *clients, string)) (*clients, string) {
t.Helper()
Expand Down Expand Up @@ -146,6 +151,7 @@ func verifyServiceAccountExistence(t *testing.T, namespace string, kubeClient *k
// TestMain initializes anything global needed by the tests. Right now this is just log and metric
// setup since the log and metric libs we're using use global state :(
func TestMain(m *testing.M) {
flag.Parse()
c := m.Run()
fmt.Fprintf(os.Stderr, "Using kubeconfig at `%s` with cluster `%s`\n", knativetest.Flags.Kubeconfig, knativetest.Flags.Cluster)
os.Exit(c)
Expand Down
4 changes: 0 additions & 4 deletions test/v1alpha1/kaniko_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ const (
revision = "1c9d566ecd13535f93789595740f20932f655905"
)

var (
skipRootUserTests = "false"
)

// TestTaskRun is an integration test that will verify a TaskRun using kaniko
func TestKanikoTaskRun(t *testing.T) {
if skipRootUserTests == "true" {
Expand Down

0 comments on commit 9b570aa

Please sign in to comment.