Skip to content

Commit 60ba449

Browse files
committed
WIP
1 parent ed0bb54 commit 60ba449

14 files changed

Lines changed: 149 additions & 42 deletions

File tree

internal/command/files.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import (
55
"net/http"
66
"os"
77
"strings"
8+
9+
"github.com/buildkite/test-engine-client/internal/runner"
810
)
911

10-
func getTestFiles(fileList string, testRunner TestRunner) ([]string, error) {
12+
func getTestFiles(fileList string, testRunner runner.TestRunner) ([]string, error) {
1113
if fileList != "" {
1214
return getTestFilesFromFile(fileList)
1315
} else {

internal/command/request_param.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/buildkite/test-engine-client/internal/config"
99
"github.com/buildkite/test-engine-client/internal/debug"
1010
"github.com/buildkite/test-engine-client/internal/plan"
11+
"github.com/buildkite/test-engine-client/internal/runner"
1112
)
1213

1314
// createRequestParam generates the parameters needed for a test plan request.
@@ -18,16 +19,16 @@ import (
1819
//
1920
// If tag filtering is enabled, all files are split into examples to support filtering.
2021
// Currently only the Pytest runner supports tag filtering.
21-
func createRequestParam(ctx context.Context, cfg *config.Config, files []string, client api.Client, runner TestRunner) (api.TestPlanParams, error) {
22+
func createRequestParam(ctx context.Context, cfg *config.Config, files []string, client api.Client, runner runner.TestRunner) (api.TestPlanParams, error) {
2223
testFiles := []plan.TestCase{}
2324
for _, file := range files {
2425
testFiles = append(testFiles, plan.TestCase{
2526
Path: file,
2627
})
2728
}
2829

29-
// Splitting files by example is only supported for rspec, cucumber, and pytest runners
30-
if runner.Name() != "RSpec" && runner.Name() != "Cucumber" && runner.Name() != "pytest" {
30+
// Short circuit here if the runner doesn't support split by example
31+
if !runner.SupportedFeatures().SplitByExample {
3132
params := api.TestPlanParams{
3233
Identifier: cfg.Identifier,
3334
Parallelism: cfg.Parallelism,
@@ -86,7 +87,7 @@ func createRequestParam(ctx context.Context, cfg *config.Config, files []string,
8687
}
8788

8889
// Splits all the test files into examples to support tag filtering.
89-
func splitAllFiles(files []plan.TestCase, runner TestRunner) (api.TestPlanParamsTest, error) {
90+
func splitAllFiles(files []plan.TestCase, runner runner.TestRunner) (api.TestPlanParamsTest, error) {
9091
debug.Printf("Splitting all %d files", len(files))
9192
filePaths := make([]string, 0, len(files))
9293
for _, file := range files {
@@ -108,7 +109,7 @@ func splitAllFiles(files []plan.TestCase, runner TestRunner) (api.TestPlanParams
108109
// filterAndSplitFiles filters the test files through the Test Engine API and splits the filtered files into examples.
109110
// It returns the test plan parameters with the examples from the filtered files and the remaining files.
110111
// An error is returned if there is a failure in any of the process.
111-
func filterAndSplitFiles(ctx context.Context, cfg *config.Config, client api.Client, files []plan.TestCase, runner TestRunner) (api.TestPlanParamsTest, error) {
112+
func filterAndSplitFiles(ctx context.Context, cfg *config.Config, client api.Client, files []plan.TestCase, runner runner.TestRunner) (api.TestPlanParamsTest, error) {
112113
// Filter files that need to be split.
113114
debug.Printf("Filtering %d files", len(files))
114115
filteredFiles, err := client.FilterTests(ctx, cfg.SuiteSlug, api.FilterTestsParams{

internal/command/run.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@ import (
1919
"github.com/olekukonko/tablewriter"
2020
)
2121

22-
type TestRunner interface {
23-
// Run takes testCases as input, executes the test against the test cases, and mutates the runner.RunResult with the test results.
24-
Run(result *runner.RunResult, testCases []plan.TestCase, retry bool) error
25-
// GetExamples discovers all tests within given files.
26-
// This function is only used for split by example use case. Currently only supported by RSpec.
27-
GetExamples(files []string) ([]plan.TestCase, error)
28-
// GetFiles discover all test files that the runner should execute.
29-
// This is sent to server-side when creating test plan.
30-
// This is also used to obtain a fallback non-intelligent test splitting mechanism.
31-
GetFiles() ([]string, error)
32-
Name() string
33-
}
34-
3522
const Logo = `
3623
______ ______ _____
3724
___ /____ /___ /____________
@@ -206,7 +193,7 @@ func sendMetadata(ctx context.Context, apiClient *api.Client, cfg *config.Config
206193
// For next reader, there is a small caveat with current implementation:
207194
// - testCases and timeline are both expected to be mutated.
208195
// - testCases in this case serve both as input and output -> we should probably change it.
209-
func runTestsWithRetry(testRunner TestRunner, testsCases *[]plan.TestCase, maxRetries int, mutedTests []plan.TestCase, timeline *[]api.Timeline, retryForMutedTest bool, failOnNoTests bool) (runner.RunResult, error) {
196+
func runTestsWithRetry(testRunner runner.TestRunner, testsCases *[]plan.TestCase, maxRetries int, mutedTests []plan.TestCase, timeline *[]api.Timeline, retryForMutedTest bool, failOnNoTests bool) (runner.RunResult, error) {
210197
attemptCount := 0
211198

212199
// Create a new run result with muted tests to keep track of the results.
@@ -293,7 +280,7 @@ func logSignalAndExit(name string, signal syscall.Signal) {
293280

294281
// fetchOrCreateTestPlan fetches a test plan from the server, or creates a
295282
// fallback plan if the server is unavailable or returns an error plan.
296-
func fetchOrCreateTestPlan(ctx context.Context, apiClient *api.Client, cfg *config.Config, files []string, testRunner TestRunner) (plan.TestPlan, error) {
283+
func fetchOrCreateTestPlan(ctx context.Context, apiClient *api.Client, cfg *config.Config, files []string, testRunner runner.TestRunner) (plan.TestPlan, error) {
297284
debug.Println("Fetching test plan")
298285

299286
// Fetch the plan from the server's cache.

internal/runner/cucumber.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ func NewCucumber(c RunnerConfig) Cucumber {
4545
}
4646
}
4747

48+
func (c Cucumber) SupportedFeatures() SupportedFeatures {
49+
return SupportedFeatures{
50+
SplitByFile: true,
51+
SplitByExample: true,
52+
FilterTestFiles: true,
53+
AutoRetry: true,
54+
Mute: true,
55+
Skip: true,
56+
}
57+
}
58+
4859
func (c Cucumber) Name() string {
4960
return "Cucumber"
5061
}

internal/runner/custom.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ func NewCustom(r RunnerConfig) (Custom, error) {
3333
}, nil
3434
}
3535

36+
func (c Custom) SupportedFeatures() SupportedFeatures {
37+
return SupportedFeatures{
38+
SplitByFile: true,
39+
SplitByExample: false,
40+
FilterTestFiles: true,
41+
AutoRetry: false,
42+
Mute: true,
43+
Skip: false,
44+
}
45+
}
46+
3647
func (r Custom) Name() string {
3748
return "Custom test runner"
3849
}

internal/runner/cypress.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ func NewCypress(c RunnerConfig) Cypress {
3333
}
3434
}
3535

36+
func (c Cypress) SupportedFeatures() SupportedFeatures {
37+
return SupportedFeatures{
38+
SplitByFile: true,
39+
SplitByExample: false,
40+
FilterTestFiles: true,
41+
AutoRetry: false,
42+
Mute: false,
43+
Skip: false,
44+
}
45+
}
46+
3647
func (c Cypress) Run(result *RunResult, testCases []plan.TestCase, retry bool) error {
3748
testPaths := make([]string, len(testCases))
3849
for i, tc := range testCases {

internal/runner/detector.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,8 @@ import (
44
"fmt"
55

66
"github.com/buildkite/test-engine-client/internal/config"
7-
"github.com/buildkite/test-engine-client/internal/plan"
87
)
98

10-
type RunnerConfig struct {
11-
TestRunner string
12-
TestCommand string
13-
TestFilePattern string
14-
TestFileExcludePattern string
15-
RetryTestCommand string
16-
TagFilters string
17-
// ResultPath is used internally so bktec can read result from Test Runner.
18-
// User typically don't need to worry about setting this except in in RSpec and playwright.
19-
// In playwright, for example, it can only be configured via a config file, therefore it's mandatory for user to set.
20-
ResultPath string
21-
}
22-
23-
type TestRunner interface {
24-
Run(result *RunResult, testCases []plan.TestCase, retry bool) error
25-
GetExamples(files []string) ([]plan.TestCase, error)
26-
GetFiles() ([]string, error)
27-
Name() string
28-
}
29-
309
func DetectRunner(cfg *config.Config) (TestRunner, error) {
3110
runnerConfig := RunnerConfig{
3211
TestRunner: cfg.TestRunner,

internal/runner/gotest.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ func NewGoTest(c RunnerConfig) GoTest {
3232
}
3333
}
3434

35+
func (g GoTest) SupportedFeatures() SupportedFeatures {
36+
return SupportedFeatures{
37+
SplitByFile: false,
38+
SplitByExample: false,
39+
FilterTestFiles: false,
40+
AutoRetry: true,
41+
Mute: true,
42+
Skip: false,
43+
}
44+
}
45+
3546
func (g GoTest) Name() string {
3647
return "gotest"
3748
}

internal/runner/jest.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ func NewJest(j RunnerConfig) Jest {
3838
}
3939
}
4040

41+
func (j Jest) SupportedFeatures() SupportedFeatures {
42+
return SupportedFeatures{
43+
SplitByFile: true,
44+
SplitByExample: false,
45+
FilterTestFiles: true,
46+
AutoRetry: true,
47+
Mute: true,
48+
Skip: false,
49+
}
50+
}
51+
4152
func (j Jest) Name() string {
4253
return "Jest"
4354
}

internal/runner/playwright.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ func NewPlaywright(p RunnerConfig) Playwright {
3535
}
3636
}
3737

38+
func (p Playwright) SupportedFeatures() SupportedFeatures {
39+
return SupportedFeatures{
40+
SplitByFile: true,
41+
SplitByExample: false,
42+
FilterTestFiles: true,
43+
AutoRetry: true,
44+
Mute: true,
45+
Skip: false,
46+
}
47+
}
48+
3849
func (p Playwright) Run(result *RunResult, testCases []plan.TestCase, retry bool) error {
3950
testPaths := make([]string, len(testCases))
4051
for i, tc := range testCases {

0 commit comments

Comments
 (0)