(t *testing.T)
| 64 | ) |
| 65 | |
| 66 | func TestIntegration(t *testing.T) { |
| 67 | if testing.Short() { |
| 68 | t.Skip("skipping integration test in short mode") |
| 69 | } |
| 70 | if os.Getenv("GO_BUILDER_NAME") != "" { |
| 71 | // To start off, run on longtest builders, not longtest-race ones. |
| 72 | if race() { |
| 73 | t.Skip("skipping integration test in race mode on builders") |
| 74 | } |
| 75 | // When on a builder, run even if it's not explicitly requested |
| 76 | // provided our caller isn't already running it. |
| 77 | if os.Getenv("GO_PROTOBUF_INTEGRATION_TEST_RUNNING") == "1" { |
| 78 | t.Skip("protobuf integration test is already running, skipping nested invocation") |
| 79 | } |
| 80 | os.Setenv("GO_PROTOBUF_INTEGRATION_TEST_RUNNING", "1") |
| 81 | } else if flag.Lookup("test.run").Value.String() != "^TestIntegration$" { |
| 82 | t.Skip("not running integration test if not explicitly requested via test.bash") |
| 83 | } |
| 84 | |
| 85 | mustInitDeps(t) |
| 86 | mustHandleFlags(t) |
| 87 | |
| 88 | // Report dirt in the working tree quickly, rather than after |
| 89 | // going through all the presubmits. |
| 90 | // |
| 91 | // Fail the test late, so we can test uncommitted changes with -failfast. |
| 92 | gitDiff := mustRunCommand(t, "git", "diff", "HEAD") |
| 93 | if strings.TrimSpace(gitDiff) != "" { |
| 94 | fmt.Printf("WARNING: working tree contains uncommitted changes:\n%v\n", gitDiff) |
| 95 | } |
| 96 | gitUntracked := mustRunCommand(t, "git", "ls-files", "--others", "--exclude-standard") |
| 97 | if strings.TrimSpace(gitUntracked) != "" { |
| 98 | fmt.Printf("WARNING: working tree contains untracked files:\n%v\n", gitUntracked) |
| 99 | } |
| 100 | |
| 101 | // Do the relatively fast checks up-front. |
| 102 | t.Run("GeneratedGoFiles", func(t *testing.T) { |
| 103 | diff := mustRunCommand(t, "go", "run", "-tags", "protolegacy", "./internal/cmd/generate-types") |
| 104 | if strings.TrimSpace(diff) != "" { |
| 105 | t.Fatalf("stale generated files:\n%v", diff) |
| 106 | } |
| 107 | diff = mustRunCommand(t, "go", "run", "-tags", "protolegacy", "./internal/cmd/generate-protos") |
| 108 | if strings.TrimSpace(diff) != "" { |
| 109 | t.Fatalf("stale generated files:\n%v", diff) |
| 110 | } |
| 111 | }) |
| 112 | t.Run("FormattedGoFiles", func(t *testing.T) { |
| 113 | files := strings.Split(strings.TrimSpace(mustRunCommand(t, "git", "ls-files", "*.go")), "\n") |
| 114 | diff := mustRunCommand(t, append([]string{"gofmt", "-d"}, files...)...) |
| 115 | if strings.TrimSpace(diff) != "" { |
| 116 | t.Fatalf("unformatted source files:\n%v", diff) |
| 117 | } |
| 118 | }) |
| 119 | t.Run("GeneratedVet", func(t *testing.T) { |
| 120 | files := strings.Split(strings.TrimSpace(mustRunCommand(t, "go", "list", "./internal/testprotos/...")), "\n") |
| 121 | filtered := make([]string, 0, len(files)) |
| 122 | for _, f := range files { |
| 123 | if strings.Contains(f, "/legacy/") { |
nothing calls this directly
no test coverage detected