Skip to content

Commit 370cd7b

Browse files
authored
fix smart selection in multiconfig (#219)
1 parent a2ec489 commit 370cd7b

File tree

2 files changed

+125
-1
lines changed

2 files changed

+125
-1
lines changed

pkg/driver/driver_v2.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"os"
1212
"path"
13+
"strings"
1314
"sync"
1415

1516
"github.com/LambdaTest/test-at-scale/pkg/core"
@@ -416,7 +417,7 @@ func (d *driverV2) buildDiscoveryArgs(payload *core.Payload, tasConfig *core.TAS
416417
TestConfigFile: subModule.ConfigFile,
417418
FrameWork: subModule.Framework,
418419
SmartRun: tasConfig.SmartRun,
419-
Diff: diff,
420+
Diff: GetSubmoduleBasedDiff(diff, subModule.Path),
420421
DiffExists: diffExists,
421422
CWD: modulePath,
422423
}
@@ -495,3 +496,18 @@ func (d *driverV2) buildTestExecutionArgs(payload *core.Payload,
495496
CWD: modulePath,
496497
}
497498
}
499+
500+
func GetSubmoduleBasedDiff(diff map[string]int, subModulePath string) map[string]int {
501+
newDiff := map[string]int{}
502+
subModulePath = strings.TrimPrefix(subModulePath, "./")
503+
if !strings.HasSuffix(subModulePath, "/") {
504+
subModulePath += "/"
505+
}
506+
507+
for file, value := range diff {
508+
filePath := strings.TrimPrefix(file, subModulePath)
509+
510+
newDiff[filePath] = value
511+
}
512+
return newDiff
513+
}

pkg/driver/driver_v2_test.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package driver
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
type testArgs struct {
9+
name string
10+
subModulePath string
11+
diffMap map[string]int
12+
wantDiffMap map[string]int
13+
}
14+
15+
func TestGetSubmoduleBasedDiff(t *testing.T) {
16+
tests :=
17+
[]testArgs{
18+
{
19+
name: "test with subModule package included in diff 1",
20+
subModulePath: "./package/subModule-1",
21+
diffMap: map[string]int{
22+
"package/subModule-1/test/testFile1.js": 1,
23+
"package/subModule-1/test/testFile2.js": 2,
24+
"package/subModule-2/test/testFile1.js": 3,
25+
"package/subModule-2/test/testFile2.js": 4,
26+
},
27+
wantDiffMap: map[string]int{
28+
"test/testFile1.js": 1,
29+
"test/testFile2.js": 2,
30+
"package/subModule-2/test/testFile1.js": 3,
31+
"package/subModule-2/test/testFile2.js": 4,
32+
},
33+
},
34+
35+
{
36+
name: "test with subModule package included in diff 2",
37+
subModulePath: "package/subModule-1",
38+
diffMap: map[string]int{
39+
"package/subModule-1/test/testFile1.js": 1,
40+
"package/subModule-1/test/testFile2.js": 2,
41+
"package/subModule-2/test/testFile1.js": 3,
42+
"package/subModule-2/test/testFile2.js": 4,
43+
},
44+
wantDiffMap: map[string]int{
45+
"test/testFile1.js": 1,
46+
"test/testFile2.js": 2,
47+
"package/subModule-2/test/testFile1.js": 3,
48+
"package/subModule-2/test/testFile2.js": 4,
49+
},
50+
},
51+
{
52+
name: "test with subModule package included in diff 3",
53+
subModulePath: "./package/subModule-1/",
54+
diffMap: map[string]int{
55+
"package/subModule-1/test/testFile1.js": 1,
56+
"package/subModule-1/test/testFile2.js": 2,
57+
"package/subModule-2/test/testFile1.js": 3,
58+
"package/subModule-2/test/testFile2.js": 4,
59+
},
60+
wantDiffMap: map[string]int{
61+
"test/testFile1.js": 1,
62+
"test/testFile2.js": 2,
63+
"package/subModule-2/test/testFile1.js": 3,
64+
"package/subModule-2/test/testFile2.js": 4,
65+
},
66+
},
67+
{
68+
name: "test with subModule package included in diff 4",
69+
subModulePath: "package/subModule-1/",
70+
diffMap: map[string]int{
71+
"package/subModule-1/test/testFile1.js": 1,
72+
"package/subModule-1/test/testFile2.js": 2,
73+
"package/subModule-2/test/testFile1.js": 3,
74+
"package/subModule-2/test/testFile2.js": 4,
75+
},
76+
wantDiffMap: map[string]int{
77+
"test/testFile1.js": 1,
78+
"test/testFile2.js": 2,
79+
"package/subModule-2/test/testFile1.js": 3,
80+
"package/subModule-2/test/testFile2.js": 4,
81+
},
82+
},
83+
{
84+
name: "test with subModule package not included in diff ",
85+
subModulePath: "package/subModule-1/",
86+
diffMap: map[string]int{
87+
"package/subModule-2/test/testFile1.js": 1,
88+
"package/subModule-2/test/testFile2.js": 2,
89+
"package/subModule-2/test/testFile3.js": 3,
90+
"package/subModule-2/test/testFile4.js": 4,
91+
},
92+
wantDiffMap: map[string]int{
93+
"package/subModule-2/test/testFile1.js": 1,
94+
"package/subModule-2/test/testFile2.js": 2,
95+
"package/subModule-2/test/testFile3.js": 3,
96+
"package/subModule-2/test/testFile4.js": 4,
97+
},
98+
},
99+
}
100+
for _, test := range tests {
101+
t.Run(test.name, func(t *testing.T) {
102+
actualMap := GetSubmoduleBasedDiff(test.diffMap, test.subModulePath)
103+
if !reflect.DeepEqual(actualMap, test.wantDiffMap) {
104+
t.Errorf("not equal wanted %+v , got %+v", test.diffMap, actualMap)
105+
}
106+
})
107+
}
108+
}

0 commit comments

Comments
 (0)