Skip to content

Commit 8b18a64

Browse files
authored
Merge pull request #15 from DataDog/anmarchenko/test_discovery_format_changes
[SDTEST-2709] Tests discovery: change format of tests.json file
2 parents e4841fd + 28f32d9 commit 8b18a64

File tree

8 files changed

+64
-52
lines changed

8 files changed

+64
-52
lines changed

internal/framework/rspec.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func (r *RSpec) createDiscoveryCommand() *exec.Cmd {
4646
command, baseArgs := r.getRSpecCommand()
4747
args := append(baseArgs, "--format", "progress", "--dry-run")
4848

49-
// this is a constant, no
5049
// no-dd-sa:go-security/command-injection
5150
cmd := exec.Command(command, args...)
5251
cmd.Env = append(

internal/framework/rspec_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,17 @@ func TestRSpec_DiscoverTests_Success(t *testing.T) {
194194

195195
testData := []testoptimization.Test{
196196
{
197-
FQN: "spec/models/user_spec.rb[1:1]",
198197
Name: "User should be valid",
199198
Suite: "User",
200-
SourceFile: "spec/models/user_spec.rb",
199+
Module: "rspec",
200+
Parameters: "{a: 1}",
201201
SuiteSourceFile: "spec/models/user_spec.rb",
202202
},
203203
{
204-
FQN: "spec/controllers/users_controller_spec.rb[1:1]",
205204
Name: "UsersController GET index should return success",
206205
Suite: "UsersController",
207-
SourceFile: "spec/controllers/users_controller_spec.rb",
206+
Module: "rspec",
207+
Parameters: "{a: 2}",
208208
SuiteSourceFile: "spec/controllers/users_controller_spec.rb",
209209
},
210210
}
@@ -259,17 +259,20 @@ func TestRSpec_DiscoverTests_Success(t *testing.T) {
259259
continue
260260
}
261261
actual := tests[i]
262-
if actual.FQN != expected.FQN {
263-
t.Errorf("test[%d].FQN: expected %q, got %q", i, expected.FQN, actual.FQN)
262+
if actual.Parameters != expected.Parameters {
263+
t.Errorf("test[%d].Parameters: expected %q, got %q", i, expected.Parameters, actual.Parameters)
264264
}
265265
if actual.Name != expected.Name {
266266
t.Errorf("test[%d].Name: expected %q, got %q", i, expected.Name, actual.Name)
267267
}
268268
if actual.Suite != expected.Suite {
269269
t.Errorf("test[%d].Suite: expected %q, got %q", i, expected.Suite, actual.Suite)
270270
}
271-
if actual.SourceFile != expected.SourceFile {
272-
t.Errorf("test[%d].SourceFile: expected %q, got %q", i, expected.SourceFile, actual.SourceFile)
271+
if actual.Module != expected.Module {
272+
t.Errorf("test[%d].Module: expected %q, got %q", i, expected.Module, actual.Module)
273+
}
274+
if actual.SuiteSourceFile != expected.SuiteSourceFile {
275+
t.Errorf("test[%d].SuiteSourceFile: expected %q, got %q", i, expected.SuiteSourceFile, actual.SuiteSourceFile)
273276
}
274277
}
275278
}

internal/runner/dd_test_optimization.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ func (tr *TestRunner) PrepareTestOptimization(ctx context.Context) error {
6666

6767
tr.testFiles = make(map[string]int)
6868
for _, test := range discoveredTests {
69-
if !skippableTests[test.FQN] {
70-
slog.Debug("Test is not skipped", "test", test.FQN, "sourceFile", test.SuiteSourceFile)
69+
if !skippableTests[test.FQN()] {
70+
slog.Debug("Test is not skipped", "test", test.FQN(), "sourceFile", test.SuiteSourceFile)
7171
if test.SuiteSourceFile != "" {
7272
tr.testFiles[test.SuiteSourceFile]++
7373
}

internal/runner/dd_test_optimization_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ func TestTestRunner_PrepareTestOptimization_Success(t *testing.T) {
1616
mockFramework := &MockFramework{
1717
FrameworkName: "rspec",
1818
Tests: []testoptimization.Test{
19-
{FQN: "TestSuite1.test1", SourceFile: "test/file1_test.rb", SuiteSourceFile: "test/file1_test.rb"},
20-
{FQN: "TestSuite1.test2", SourceFile: "test/file1_test.rb", SuiteSourceFile: "test/file1_test.rb"},
21-
{FQN: "TestSuite2.test3", SourceFile: "test/file2_test.rb", SuiteSourceFile: "test/file2_test.rb"},
22-
{FQN: "TestSuite3.test4", SourceFile: "test/file3_test.rb", SuiteSourceFile: "test/file3_test.rb"},
19+
{Suite: "TestSuite1", Name: "test1", Parameters: "", SuiteSourceFile: "test/file1_test.rb"},
20+
{Suite: "TestSuite1", Name: "test2", Parameters: "", SuiteSourceFile: "test/file1_test.rb"},
21+
{Suite: "TestSuite2", Name: "test3", Parameters: "", SuiteSourceFile: "test/file2_test.rb"},
22+
{Suite: "TestSuite3", Name: "test4", Parameters: "", SuiteSourceFile: "test/file3_test.rb"},
2323
},
2424
}
2525

@@ -38,8 +38,8 @@ func TestTestRunner_PrepareTestOptimization_Success(t *testing.T) {
3838

3939
mockOptimizationClient := &MockTestOptimizationClient{
4040
SkippableTests: map[string]bool{
41-
"TestSuite1.test2": true, // Skip test2
42-
"TestSuite3.test4": true, // Skip test4
41+
"TestSuite1.test2.": true, // Skip test2
42+
"TestSuite3.test4.": true, // Skip test4
4343
},
4444
}
4545

@@ -145,7 +145,7 @@ func TestTestRunner_PrepareTestOptimization_OptimizationClientInitError(t *testi
145145

146146
mockFramework := &MockFramework{
147147
Tests: []testoptimization.Test{
148-
{FQN: "test1", SourceFile: "file1.rb", SuiteSourceFile: "file1.rb"},
148+
{Suite: "", Name: "test1", Parameters: "", SuiteSourceFile: "file1.rb"},
149149
},
150150
}
151151

@@ -274,8 +274,8 @@ func TestTestRunner_PrepareTestOptimization_AllTestsSkipped(t *testing.T) {
274274

275275
mockFramework := &MockFramework{
276276
Tests: []testoptimization.Test{
277-
{FQN: "test1", SourceFile: "file1.rb", SuiteSourceFile: "file1.rb"},
278-
{FQN: "test2", SourceFile: "file2.rb", SuiteSourceFile: "file2.rb"},
277+
{Suite: "", Name: "test1", Parameters: "", SuiteSourceFile: "file1.rb"},
278+
{Suite: "", Name: "test2", Parameters: "", SuiteSourceFile: "file2.rb"},
279279
},
280280
}
281281

@@ -287,8 +287,8 @@ func TestTestRunner_PrepareTestOptimization_AllTestsSkipped(t *testing.T) {
287287
mockPlatformDetector := &MockPlatformDetector{Platform: mockPlatform}
288288
mockOptimizationClient := &MockTestOptimizationClient{
289289
SkippableTests: map[string]bool{
290-
"test1": true,
291-
"test2": true,
290+
".test1.": true,
291+
".test2.": true,
292292
},
293293
}
294294

internal/runner/runner_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ func TestTestRunner_Setup_WithParallelRunners(t *testing.T) {
222222
mockFramework := &MockFramework{
223223
FrameworkName: "rspec",
224224
Tests: []testoptimization.Test{
225-
{FQN: "TestSuite1.test1", SourceFile: "test/file1_test.rb", SuiteSourceFile: "test/file1_test.rb"},
226-
{FQN: "TestSuite1.test2", SourceFile: "test/file1_test.rb", SuiteSourceFile: "test/file1_test.rb"},
227-
{FQN: "TestSuite2.test3", SourceFile: "test/file2_test.rb", SuiteSourceFile: "test/file2_test.rb"},
228-
{FQN: "TestSuite3.test4", SourceFile: "test/file3_test.rb", SuiteSourceFile: "test/file3_test.rb"},
229-
{FQN: "TestSuite4.test5", SourceFile: "test/file4_test.rb", SuiteSourceFile: "test/file4_test.rb"},
225+
{Suite: "TestSuite1", Name: "test1", Parameters: "", SuiteSourceFile: "test/file1_test.rb"},
226+
{Suite: "TestSuite1", Name: "test2", Parameters: "", SuiteSourceFile: "test/file1_test.rb"},
227+
{Suite: "TestSuite2", Name: "test3", Parameters: "", SuiteSourceFile: "test/file2_test.rb"},
228+
{Suite: "TestSuite3", Name: "test4", Parameters: "", SuiteSourceFile: "test/file3_test.rb"},
229+
{Suite: "TestSuite4", Name: "test5", Parameters: "", SuiteSourceFile: "test/file4_test.rb"},
230230
},
231231
}
232232

@@ -239,8 +239,8 @@ func TestTestRunner_Setup_WithParallelRunners(t *testing.T) {
239239
mockPlatformDetector := &MockPlatformDetector{Platform: mockPlatform}
240240
mockOptimizationClient := &MockTestOptimizationClient{
241241
SkippableTests: map[string]bool{
242-
"TestSuite1.test2": true, // Skip test2
243-
"TestSuite4.test5": true, // Skip test5
242+
"TestSuite1.test2.": true, // Skip test2
243+
"TestSuite4.test5.": true, // Skip test5
244244
},
245245
}
246246

@@ -279,8 +279,8 @@ func TestTestRunner_Setup_WithCIProvider(t *testing.T) {
279279
mockFramework := &MockFramework{
280280
FrameworkName: "rspec",
281281
Tests: []testoptimization.Test{
282-
{FQN: "TestSuite1.test1", SourceFile: "test/file1_test.rb", SuiteSourceFile: "test/file1_test.rb"},
283-
{FQN: "TestSuite2.test2", SourceFile: "test/file2_test.rb", SuiteSourceFile: "test/file2_test.rb"},
282+
{Suite: "TestSuite1", Name: "test1", Parameters: "", SuiteSourceFile: "test/file1_test.rb"},
283+
{Suite: "TestSuite2", Name: "test2", Parameters: "", SuiteSourceFile: "test/file2_test.rb"},
284284
},
285285
}
286286

@@ -341,7 +341,7 @@ func TestTestRunner_Setup_CIProviderDetectionFailure(t *testing.T) {
341341
mockFramework := &MockFramework{
342342
FrameworkName: "rspec",
343343
Tests: []testoptimization.Test{
344-
{FQN: "TestSuite1.test1", SourceFile: "test/file1_test.rb", SuiteSourceFile: "test/file1_test.rb"},
344+
{Suite: "TestSuite1", Name: "test1", Parameters: "", SuiteSourceFile: "test/file1_test.rb"},
345345
},
346346
}
347347

@@ -382,7 +382,7 @@ func TestTestRunner_Setup_CIProviderConfigureFailure(t *testing.T) {
382382
mockFramework := &MockFramework{
383383
FrameworkName: "rspec",
384384
Tests: []testoptimization.Test{
385-
{FQN: "TestSuite1.test1", SourceFile: "test/file1_test.rb", SuiteSourceFile: "test/file1_test.rb"},
385+
{Suite: "TestSuite1", Name: "test1", Parameters: "", SuiteSourceFile: "test/file1_test.rb"},
386386
},
387387
}
388388

@@ -435,8 +435,8 @@ func TestTestRunner_Setup_WithTestSplit(t *testing.T) {
435435
mockFramework := &MockFramework{
436436
FrameworkName: "rspec",
437437
Tests: []testoptimization.Test{
438-
{FQN: "TestSuite1.test1", SourceFile: "test/file1_test.rb", SuiteSourceFile: "test/file1_test.rb"},
439-
{FQN: "TestSuite2.test2", SourceFile: "test/file2_test.rb", SuiteSourceFile: "test/file2_test.rb"},
438+
{Suite: "TestSuite1", Name: "test1", Parameters: "", SuiteSourceFile: "test/file1_test.rb"},
439+
{Suite: "TestSuite2", Name: "test2", Parameters: "", SuiteSourceFile: "test/file2_test.rb"},
440440
},
441441
}
442442

@@ -509,10 +509,10 @@ func TestTestRunner_Setup_WithTestSplit(t *testing.T) {
509509
mockFramework := &MockFramework{
510510
FrameworkName: "rspec",
511511
Tests: []testoptimization.Test{
512-
{FQN: "TestSuite1.test1", SourceFile: "test/file1_test.rb", SuiteSourceFile: "test/file1_test.rb"},
513-
{FQN: "TestSuite1.test2", SourceFile: "test/file1_test.rb", SuiteSourceFile: "test/file1_test.rb"}, // 2 tests in file1
514-
{FQN: "TestSuite2.test3", SourceFile: "test/file2_test.rb", SuiteSourceFile: "test/file2_test.rb"}, // 1 test in file2
515-
{FQN: "TestSuite3.test4", SourceFile: "test/file3_test.rb", SuiteSourceFile: "test/file3_test.rb"}, // 1 test in file3
512+
{Suite: "TestSuite1", Name: "test1", Parameters: "", SuiteSourceFile: "test/file1_test.rb"},
513+
{Suite: "TestSuite1", Name: "test2", Parameters: "", SuiteSourceFile: "test/file1_test.rb"}, // 2 tests in file1
514+
{Suite: "TestSuite2", Name: "test3", Parameters: "", SuiteSourceFile: "test/file2_test.rb"}, // 1 test in file2
515+
{Suite: "TestSuite3", Name: "test4", Parameters: "", SuiteSourceFile: "test/file3_test.rb"}, // 1 test in file3
516516
},
517517
}
518518

internal/testoptimization/client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,12 @@ func (c *DatadogClient) GetSkippableTests() map[string]bool {
119119
for _, suites := range skippableTests {
120120
for _, tests := range suites {
121121
for _, test := range tests {
122-
testFQN := c.buildTestFQN(test.Suite, test.Name, test.Parameters)
123-
skippedTests[testFQN] = true
122+
t := Test{
123+
Name: test.Name,
124+
Suite: test.Suite,
125+
Parameters: test.Parameters,
126+
}
127+
skippedTests[t.FQN()] = true
124128
}
125129
}
126130
}
@@ -167,7 +171,3 @@ func (c *DatadogClient) StoreCacheAndExit() {
167171

168172
c.integrations.ExitCiVisibility()
169173
}
170-
171-
func (c *DatadogClient) buildTestFQN(suite, test, parameters string) string {
172-
return fmt.Sprintf("%s.%s.%s", suite, test, parameters)
173-
}

internal/testoptimization/client_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,7 @@ func TestDatadogClient_StoreCacheAndExit_WritesSettingsFile(t *testing.T) {
277277
}
278278
}
279279

280-
func TestDatadogClient_buildTestFQN(t *testing.T) {
281-
client := NewDatadogClient()
282-
280+
func TestTest_FQN(t *testing.T) {
283281
testCases := []struct {
284282
suite string
285283
test string
@@ -293,9 +291,14 @@ func TestDatadogClient_buildTestFQN(t *testing.T) {
293291
}
294292

295293
for _, tc := range testCases {
296-
result := client.buildTestFQN(tc.suite, tc.test, tc.parameters)
294+
test := Test{
295+
Suite: tc.suite,
296+
Name: tc.test,
297+
Parameters: tc.parameters,
298+
}
299+
result := test.FQN()
297300
if result != tc.expected {
298-
t.Errorf("buildTestFQN(%q, %q, %q) = %q, expected %q",
301+
t.Errorf("Test{Suite: %q, Name: %q, Parameters: %q}.FQN() = %q, expected %q",
299302
tc.suite, tc.test, tc.parameters, result, tc.expected)
300303
}
301304
}

internal/testoptimization/types.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
package testoptimization
22

3+
import "fmt"
4+
35
type Test struct {
4-
FQN string `json:"fqn"`
56
Name string `json:"name"`
67
Suite string `json:"suite"`
7-
SourceFile string `json:"sourceFile"`
8+
Module string `json:"module"`
9+
Parameters string `json:"parameters"`
810
SuiteSourceFile string `json:"suiteSourceFile"`
911
}
12+
13+
// FQN returns the fully qualified name of the test
14+
func (t *Test) FQN() string {
15+
return fmt.Sprintf("%s.%s.%s", t.Suite, t.Name, t.Parameters)
16+
}

0 commit comments

Comments
 (0)