summaryrefslogtreecommitdiffhomepage
path: root/cmd/testwrapper
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/testwrapper')
-rw-r--r--cmd/testwrapper/args_test.go194
-rw-r--r--cmd/testwrapper/flakytest/flakytest.go88
-rw-r--r--cmd/testwrapper/flakytest/flakytest_test.go86
3 files changed, 184 insertions, 184 deletions
diff --git a/cmd/testwrapper/args_test.go b/cmd/testwrapper/args_test.go
index 10063d7bc..f7f30a7eb 100644
--- a/cmd/testwrapper/args_test.go
+++ b/cmd/testwrapper/args_test.go
@@ -1,97 +1,97 @@
-// Copyright (c) Tailscale Inc & AUTHORS
-// SPDX-License-Identifier: BSD-3-Clause
-
-package main
-
-import (
- "slices"
- "testing"
-)
-
-func TestSplitArgs(t *testing.T) {
- tests := []struct {
- name string
- in []string
- pre, pkgs, post []string
- }{
- {
- name: "empty",
- },
- {
- name: "all",
- in: []string{"-v", "pkg1", "pkg2", "-run", "TestFoo", "-timeout=20s"},
- pre: []string{"-v"},
- pkgs: []string{"pkg1", "pkg2"},
- post: []string{"-run", "TestFoo", "-timeout=20s"},
- },
- {
- name: "only_pkgs",
- in: []string{"./..."},
- pkgs: []string{"./..."},
- },
- {
- name: "pkgs_and_post",
- in: []string{"pkg1", "-run", "TestFoo"},
- pkgs: []string{"pkg1"},
- post: []string{"-run", "TestFoo"},
- },
- {
- name: "pkgs_and_post",
- in: []string{"-v", "pkg2"},
- pre: []string{"-v"},
- pkgs: []string{"pkg2"},
- },
- {
- name: "only_args",
- in: []string{"-v", "-run=TestFoo"},
- pre: []string{"-run", "TestFoo", "-v"}, // sorted
- },
- {
- name: "space_in_pre_arg",
- in: []string{"-run", "TestFoo", "./cmd/testwrapper"},
- pre: []string{"-run", "TestFoo"},
- pkgs: []string{"./cmd/testwrapper"},
- },
- {
- name: "space_in_arg",
- in: []string{"-exec", "sudo -E", "./cmd/testwrapper"},
- pre: []string{"-exec", "sudo -E"},
- pkgs: []string{"./cmd/testwrapper"},
- },
- {
- name: "test-arg",
- in: []string{"-exec", "sudo -E", "./cmd/testwrapper", "--", "--some-flag"},
- pre: []string{"-exec", "sudo -E"},
- pkgs: []string{"./cmd/testwrapper"},
- post: []string{"--", "--some-flag"},
- },
- {
- name: "dupe-args",
- in: []string{"-v", "-v", "-race", "-race", "./cmd/testwrapper", "--", "--some-flag"},
- pre: []string{"-race", "-v"},
- pkgs: []string{"./cmd/testwrapper"},
- post: []string{"--", "--some-flag"},
- },
- }
-
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- pre, pkgs, post, err := splitArgs(tt.in)
- if err != nil {
- t.Fatal(err)
- }
- if !slices.Equal(pre, tt.pre) {
- t.Errorf("pre = %q; want %q", pre, tt.pre)
- }
- if !slices.Equal(pkgs, tt.pkgs) {
- t.Errorf("pattern = %q; want %q", pkgs, tt.pkgs)
- }
- if !slices.Equal(post, tt.post) {
- t.Errorf("post = %q; want %q", post, tt.post)
- }
- if t.Failed() {
- t.Logf("SplitArgs(%q) = %q %q %q", tt.in, pre, pkgs, post)
- }
- })
- }
-}
+// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+package main
+
+import (
+ "slices"
+ "testing"
+)
+
+func TestSplitArgs(t *testing.T) {
+ tests := []struct {
+ name string
+ in []string
+ pre, pkgs, post []string
+ }{
+ {
+ name: "empty",
+ },
+ {
+ name: "all",
+ in: []string{"-v", "pkg1", "pkg2", "-run", "TestFoo", "-timeout=20s"},
+ pre: []string{"-v"},
+ pkgs: []string{"pkg1", "pkg2"},
+ post: []string{"-run", "TestFoo", "-timeout=20s"},
+ },
+ {
+ name: "only_pkgs",
+ in: []string{"./..."},
+ pkgs: []string{"./..."},
+ },
+ {
+ name: "pkgs_and_post",
+ in: []string{"pkg1", "-run", "TestFoo"},
+ pkgs: []string{"pkg1"},
+ post: []string{"-run", "TestFoo"},
+ },
+ {
+ name: "pkgs_and_post",
+ in: []string{"-v", "pkg2"},
+ pre: []string{"-v"},
+ pkgs: []string{"pkg2"},
+ },
+ {
+ name: "only_args",
+ in: []string{"-v", "-run=TestFoo"},
+ pre: []string{"-run", "TestFoo", "-v"}, // sorted
+ },
+ {
+ name: "space_in_pre_arg",
+ in: []string{"-run", "TestFoo", "./cmd/testwrapper"},
+ pre: []string{"-run", "TestFoo"},
+ pkgs: []string{"./cmd/testwrapper"},
+ },
+ {
+ name: "space_in_arg",
+ in: []string{"-exec", "sudo -E", "./cmd/testwrapper"},
+ pre: []string{"-exec", "sudo -E"},
+ pkgs: []string{"./cmd/testwrapper"},
+ },
+ {
+ name: "test-arg",
+ in: []string{"-exec", "sudo -E", "./cmd/testwrapper", "--", "--some-flag"},
+ pre: []string{"-exec", "sudo -E"},
+ pkgs: []string{"./cmd/testwrapper"},
+ post: []string{"--", "--some-flag"},
+ },
+ {
+ name: "dupe-args",
+ in: []string{"-v", "-v", "-race", "-race", "./cmd/testwrapper", "--", "--some-flag"},
+ pre: []string{"-race", "-v"},
+ pkgs: []string{"./cmd/testwrapper"},
+ post: []string{"--", "--some-flag"},
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ pre, pkgs, post, err := splitArgs(tt.in)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !slices.Equal(pre, tt.pre) {
+ t.Errorf("pre = %q; want %q", pre, tt.pre)
+ }
+ if !slices.Equal(pkgs, tt.pkgs) {
+ t.Errorf("pattern = %q; want %q", pkgs, tt.pkgs)
+ }
+ if !slices.Equal(post, tt.post) {
+ t.Errorf("post = %q; want %q", post, tt.post)
+ }
+ if t.Failed() {
+ t.Logf("SplitArgs(%q) = %q %q %q", tt.in, pre, pkgs, post)
+ }
+ })
+ }
+}
diff --git a/cmd/testwrapper/flakytest/flakytest.go b/cmd/testwrapper/flakytest/flakytest.go
index 494ed080b..e5e21dd21 100644
--- a/cmd/testwrapper/flakytest/flakytest.go
+++ b/cmd/testwrapper/flakytest/flakytest.go
@@ -1,44 +1,44 @@
-// Copyright (c) Tailscale Inc & AUTHORS
-// SPDX-License-Identifier: BSD-3-Clause
-
-// Package flakytest contains test helpers for marking a test as flaky. For
-// tests run using cmd/testwrapper, a failed flaky test will cause tests to be
-// re-run a few time until they succeed or exceed our iteration limit.
-package flakytest
-
-import (
- "fmt"
- "os"
- "regexp"
- "testing"
-)
-
-// FlakyTestLogMessage is a sentinel value that is printed to stderr when a
-// flaky test is marked. This is used by cmd/testwrapper to detect flaky tests
-// and retry them.
-const FlakyTestLogMessage = "flakytest: this is a known flaky test"
-
-// FlakeAttemptEnv is an environment variable that is set by cmd/testwrapper
-// when a flaky test is being (re)tried. It contains the attempt number,
-// starting at 1.
-const FlakeAttemptEnv = "TS_TESTWRAPPER_ATTEMPT"
-
-var issueRegexp = regexp.MustCompile(`\Ahttps://github\.com/tailscale/[a-zA-Z0-9_.-]+/issues/\d+\z`)
-
-// Mark sets the current test as a flaky test, such that if it fails, it will
-// be retried a few times on failure. issue must be a GitHub issue that tracks
-// the status of the flaky test being marked, of the format:
-//
-// https://github.com/tailscale/myRepo-H3re/issues/12345
-func Mark(t testing.TB, issue string) {
- if !issueRegexp.MatchString(issue) {
- t.Fatalf("bad issue format: %q", issue)
- }
- if _, ok := os.LookupEnv(FlakeAttemptEnv); ok {
- // We're being run under cmd/testwrapper so send our sentinel message
- // to stderr. (We avoid doing this when the env is absent to avoid
- // spamming people running tests without the wrapper)
- fmt.Fprintf(os.Stderr, "%s: %s\n", FlakyTestLogMessage, issue)
- }
- t.Logf("flakytest: issue tracking this flaky test: %s", issue)
-}
+// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+// Package flakytest contains test helpers for marking a test as flaky. For
+// tests run using cmd/testwrapper, a failed flaky test will cause tests to be
+// re-run a few time until they succeed or exceed our iteration limit.
+package flakytest
+
+import (
+ "fmt"
+ "os"
+ "regexp"
+ "testing"
+)
+
+// FlakyTestLogMessage is a sentinel value that is printed to stderr when a
+// flaky test is marked. This is used by cmd/testwrapper to detect flaky tests
+// and retry them.
+const FlakyTestLogMessage = "flakytest: this is a known flaky test"
+
+// FlakeAttemptEnv is an environment variable that is set by cmd/testwrapper
+// when a flaky test is being (re)tried. It contains the attempt number,
+// starting at 1.
+const FlakeAttemptEnv = "TS_TESTWRAPPER_ATTEMPT"
+
+var issueRegexp = regexp.MustCompile(`\Ahttps://github\.com/tailscale/[a-zA-Z0-9_.-]+/issues/\d+\z`)
+
+// Mark sets the current test as a flaky test, such that if it fails, it will
+// be retried a few times on failure. issue must be a GitHub issue that tracks
+// the status of the flaky test being marked, of the format:
+//
+// https://github.com/tailscale/myRepo-H3re/issues/12345
+func Mark(t testing.TB, issue string) {
+ if !issueRegexp.MatchString(issue) {
+ t.Fatalf("bad issue format: %q", issue)
+ }
+ if _, ok := os.LookupEnv(FlakeAttemptEnv); ok {
+ // We're being run under cmd/testwrapper so send our sentinel message
+ // to stderr. (We avoid doing this when the env is absent to avoid
+ // spamming people running tests without the wrapper)
+ fmt.Fprintf(os.Stderr, "%s: %s\n", FlakyTestLogMessage, issue)
+ }
+ t.Logf("flakytest: issue tracking this flaky test: %s", issue)
+}
diff --git a/cmd/testwrapper/flakytest/flakytest_test.go b/cmd/testwrapper/flakytest/flakytest_test.go
index 85e77a939..551352f6a 100644
--- a/cmd/testwrapper/flakytest/flakytest_test.go
+++ b/cmd/testwrapper/flakytest/flakytest_test.go
@@ -1,43 +1,43 @@
-// Copyright (c) Tailscale Inc & AUTHORS
-// SPDX-License-Identifier: BSD-3-Clause
-
-package flakytest
-
-import (
- "os"
- "testing"
-)
-
-func TestIssueFormat(t *testing.T) {
- testCases := []struct {
- issue string
- want bool
- }{
- {"https://github.com/tailscale/cOrp/issues/1234", true},
- {"https://github.com/otherproject/corp/issues/1234", false},
- {"https://github.com/tailscale/corp/issues/", false},
- }
- for _, testCase := range testCases {
- if issueRegexp.MatchString(testCase.issue) != testCase.want {
- ss := ""
- if !testCase.want {
- ss = " not"
- }
- t.Errorf("expected issueRegexp to%s match %q", ss, testCase.issue)
- }
- }
-}
-
-// TestFlakeRun is a test that fails when run in the testwrapper
-// for the first time, but succeeds on the second run.
-// It's used to test whether the testwrapper retries flaky tests.
-func TestFlakeRun(t *testing.T) {
- Mark(t, "https://github.com/tailscale/tailscale/issues/0") // random issue
- e := os.Getenv(FlakeAttemptEnv)
- if e == "" {
- t.Skip("not running in testwrapper")
- }
- if e == "1" {
- t.Fatal("First run in testwrapper, failing so that test is retried. This is expected.")
- }
-}
+// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+package flakytest
+
+import (
+ "os"
+ "testing"
+)
+
+func TestIssueFormat(t *testing.T) {
+ testCases := []struct {
+ issue string
+ want bool
+ }{
+ {"https://github.com/tailscale/cOrp/issues/1234", true},
+ {"https://github.com/otherproject/corp/issues/1234", false},
+ {"https://github.com/tailscale/corp/issues/", false},
+ }
+ for _, testCase := range testCases {
+ if issueRegexp.MatchString(testCase.issue) != testCase.want {
+ ss := ""
+ if !testCase.want {
+ ss = " not"
+ }
+ t.Errorf("expected issueRegexp to%s match %q", ss, testCase.issue)
+ }
+ }
+}
+
+// TestFlakeRun is a test that fails when run in the testwrapper
+// for the first time, but succeeds on the second run.
+// It's used to test whether the testwrapper retries flaky tests.
+func TestFlakeRun(t *testing.T) {
+ Mark(t, "https://github.com/tailscale/tailscale/issues/0") // random issue
+ e := os.Getenv(FlakeAttemptEnv)
+ if e == "" {
+ t.Skip("not running in testwrapper")
+ }
+ if e == "1" {
+ t.Fatal("First run in testwrapper, failing so that test is retried. This is expected.")
+ }
+}