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 <vdemeest@redhat.com>
  • Loading branch information
vdemeester authored and tekton-robot committed Mar 30, 2020
1 parent 4e4884f commit 8a9036b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 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
11 changes: 1 addition & 10 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,17 +43,9 @@ 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" {
if skipRootUserTests {
t.Skip("Skip test as skipRootUserTests set to 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
6 changes: 1 addition & 5 deletions test/v1alpha1/kaniko_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@ 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" {
if skipRootUserTests {
t.Skip("Skip test as skipRootUserTests set to true")
}

Expand Down

0 comments on commit 8a9036b

Please sign in to comment.