Skip to content

Commit 9d56e02

Browse files
invidiancpuguy83
authored andcommitted
test: target package instead of container where possible
That should make tests more targetted for their intended scope. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
1 parent f551699 commit 9d56e02

3 files changed

Lines changed: 37 additions & 39 deletions

File tree

test/custom_repo_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ func testCustomRepo(ctx context.Context, t *testing.T, workerCfg workerConfig, t
154154
sr = newSolveRequest(
155155
withSpec(ctx, t, getSpec(depSpec, nil, repoPath, "public.key")),
156156
withBuildContext(ctx, t, "test-repo", repoState),
157-
withBuildTarget(targetCfg.Container),
158-
withPlatformPtr(workerCfg.Platform),
157+
withBuildTarget(targetCfg.Package),
159158
)
160159

161160
_, err := gwc.Solve(ctx, sr)
@@ -204,8 +203,7 @@ func testCustomRepo(ctx context.Context, t *testing.T, workerCfg workerConfig, t
204203
withSpec(ctx, t, spec),
205204
withBuildContext(ctx, t, "test-repo", repoState),
206205
withBuildContext(ctx, t, "repo-public-key", gpgKey),
207-
withBuildTarget(targetCfg.Container),
208-
withPlatformPtr(workerCfg.Platform),
206+
withBuildTarget(targetCfg.Package),
209207
)
210208

211209
res := solveT(ctx, t, gwc, sr)

test/linux_target_test.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func testLinuxDistro(ctx context.Context, t *testing.T, testConfig testLinuxConf
167167
}
168168

169169
testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) {
170-
sr := newSolveRequest(withSpec(ctx, t, &spec), withBuildTarget(testConfig.Target.Container))
170+
sr := newSolveRequest(withSpec(ctx, t, &spec), withBuildTarget(testConfig.Target.Package))
171171
sr.Evaluate = true
172172
_, err := gwc.Solve(ctx, sr)
173173
var xErr *moby_buildkit_v1_frontend.ExitError
@@ -252,7 +252,7 @@ echo "$BAR" > bar.txt
252252
testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) {
253253
sr := newSolveRequest(
254254
withSpec(ctx, t, &spec),
255-
withBuildTarget(testConfig.Target.Container),
255+
withBuildTarget(testConfig.Target.Package),
256256
)
257257
solveT(ctx, t, gwc, sr)
258258
})
@@ -489,7 +489,7 @@ index 0000000..5260cb1
489489
testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) {
490490
sr := newSolveRequest(
491491
withSpec(ctx, t, &spec),
492-
withBuildTarget(testConfig.Target.Container),
492+
withBuildTarget(testConfig.Target.Package),
493493
withBuildContext(ctx, t, patchContextName, patchContext),
494494
)
495495
sr.Evaluate = true
@@ -538,7 +538,7 @@ index 0000000..5260cb1
538538
testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) {
539539
sr := newSolveRequest(
540540
withSpec(ctx, t, &spec),
541-
withBuildTarget(testConfig.Target.Container),
541+
withBuildTarget(testConfig.Target.Package),
542542
)
543543
solveT(ctx, t, gwc, sr)
544544
})
@@ -616,7 +616,7 @@ index 0000000..5260cb1
616616
testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) {
617617
sr := newSolveRequest(
618618
withSpec(ctx, t, &spec),
619-
withBuildTarget(testConfig.Target.Container),
619+
withBuildTarget(testConfig.Target.Package),
620620
)
621621
solveT(ctx, t, gwc, sr)
622622
})
@@ -708,7 +708,7 @@ index 0000000..5260cb1
708708
testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) {
709709
sr := newSolveRequest(
710710
withSpec(ctx, t, &spec),
711-
withBuildTarget(testConfig.Target.Container),
711+
withBuildTarget(testConfig.Target.Package),
712712
)
713713
solveT(ctx, t, gwc, sr)
714714
})
@@ -1828,7 +1828,7 @@ WantedBy=multi-user.target
18281828
}
18291829

18301830
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
1831-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec))
1831+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec))
18321832
solveT(ctx, t, client, req)
18331833
})
18341834

@@ -1854,7 +1854,7 @@ WantedBy=multi-user.target
18541854
}
18551855

18561856
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
1857-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec))
1857+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec))
18581858
solveT(ctx, t, client, req)
18591859
})
18601860

@@ -1883,7 +1883,7 @@ WantedBy=multi-user.target
18831883
}
18841884

18851885
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
1886-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec))
1886+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec))
18871887
solveT(ctx, t, client, req)
18881888
})
18891889
})
@@ -1999,7 +1999,7 @@ Environment="FOO_ARGS=--some-foo-args"
19991999
}
20002000

20012001
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
2002-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec))
2002+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec))
20032003
solveT(ctx, t, client, req)
20042004
})
20052005
})
@@ -2056,7 +2056,7 @@ Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/boot
20562056
}
20572057

20582058
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
2059-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec))
2059+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec))
20602060
solveT(ctx, t, client, req)
20612061
})
20622062
})
@@ -2110,7 +2110,7 @@ Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/boot
21102110
}
21112111

21122112
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
2113-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec))
2113+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec))
21142114
solveT(ctx, t, client, req)
21152115
})
21162116
})
@@ -2177,7 +2177,7 @@ func main() {
21772177
}
21782178

21792179
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
2180-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec))
2180+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec))
21812181
solveT(ctx, t, client, req)
21822182
})
21832183
})
@@ -2259,7 +2259,7 @@ func main() {
22592259
}
22602260

22612261
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
2262-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt))
2262+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt))
22632263
solveT(ctx, t, client, req)
22642264
})
22652265
})
@@ -2327,7 +2327,7 @@ func main() {
23272327
}
23282328

23292329
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
2330-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt))
2330+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt))
23312331
solveT(ctx, t, client, req)
23322332
})
23332333
})
@@ -2406,7 +2406,7 @@ func True(t interface{}, value bool, msgAndArgs ...interface{}) bool {
24062406
}
24072407

24082408
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
2409-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt))
2409+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt))
24102410
solveT(ctx, t, client, req)
24112411
})
24122412
})
@@ -2472,7 +2472,7 @@ func main() {
24722472
}
24732473

24742474
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
2475-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt))
2475+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt))
24762476
solveT(ctx, t, client, req)
24772477
})
24782478
})
@@ -2556,7 +2556,7 @@ func True(t interface{}, value bool, msgAndArgs ...interface{}) bool {
25562556
}
25572557

25582558
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
2559-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt))
2559+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt))
25602560
solveT(ctx, t, client, req)
25612561
})
25622562
})
@@ -2631,7 +2631,7 @@ func main() {
26312631
}
26322632

26332633
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
2634-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt))
2634+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt))
26352635
solveT(ctx, t, client, req)
26362636
})
26372637
})
@@ -2702,7 +2702,7 @@ func main() {
27022702
}
27032703

27042704
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
2705-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt))
2705+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt))
27062706
req.Evaluate = true
27072707
solveT(ctx, t, client, req)
27082708
})
@@ -2757,7 +2757,7 @@ func main() {
27572757
}
27582758

27592759
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
2760-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec))
2760+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec))
27612761
solveT(ctx, t, client, req)
27622762
})
27632763
})
@@ -2810,7 +2810,7 @@ func main() {
28102810
}
28112811

28122812
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
2813-
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec))
2813+
req := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec))
28142814
solveT(ctx, t, client, req)
28152815
})
28162816
})
@@ -3289,7 +3289,7 @@ func main() {
32893289
}
32903290

32913291
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
3292-
sr := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec))
3292+
sr := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec))
32933293
sr.Evaluate = true
32943294
solveT(ctx, t, client, sr)
32953295
})
@@ -3416,7 +3416,7 @@ func main() {
34163416
}
34173417

34183418
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
3419-
sr := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec))
3419+
sr := newSolveRequest(withBuildTarget(testConfig.Target.Package), withSpec(ctx, t, spec))
34203420
sr.Evaluate = true
34213421
solveT(ctx, t, client, sr)
34223422
})
@@ -3632,7 +3632,7 @@ func testNodeNpmGenerator(ctx context.Context, t *testing.T, targetCfg targetCon
36323632
}
36333633

36343634
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
3635-
reqOpts := append([]srOpt{withBuildTarget(targetCfg.Container), withSpec(ctx, t, spec)}, opts...)
3635+
reqOpts := append([]srOpt{withBuildTarget(targetCfg.Package), withSpec(ctx, t, spec)}, opts...)
36363636
req := newSolveRequest(reqOpts...)
36373637
solveT(ctx, t, client, req)
36383638
})
@@ -3679,7 +3679,7 @@ func testCustomLinuxWorker(ctx context.Context, t *testing.T, targetCfg targetCo
36793679
}
36803680

36813681
// Make sure the built-in worker can't build this package
3682-
sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(targetCfg.Container))
3682+
sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(targetCfg.Package))
36833683
_, err := gwc.Solve(ctx, sr)
36843684
if err == nil {
36853685
t.Fatal("expected solve to fail")
@@ -3708,7 +3708,7 @@ func testCustomLinuxWorker(ctx context.Context, t *testing.T, targetCfg targetCo
37083708

37093709
// Now build again with our custom worker
37103710
// Note, we are solving the main spec, not depSpec here.
3711-
sr = newSolveRequest(withSpec(ctx, t, spec), withBuildContext(ctx, t, workerCfg.ContextName, worker), withBuildTarget(targetCfg.Container))
3711+
sr = newSolveRequest(withSpec(ctx, t, spec), withBuildContext(ctx, t, workerCfg.ContextName, worker), withBuildTarget(targetCfg.Package))
37123712
solveT(ctx, t, gwc, sr)
37133713

37143714
// TODO: we should have a test to make sure this also works with source policies.
@@ -3905,7 +3905,7 @@ func testLinuxLibArtirfacts(ctx context.Context, t *testing.T, cfg testLinuxConf
39053905
}
39063906

39073907
testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) {
3908-
sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Container))
3908+
sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Package))
39093909
res := solveT(ctx, t, gwc, sr)
39103910
_, err := res.SingleRef()
39113911
assert.NilError(t, err)
@@ -3960,7 +3960,7 @@ func testLinuxLibArtirfacts(ctx context.Context, t *testing.T, cfg testLinuxConf
39603960
}
39613961

39623962
testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) {
3963-
sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Container))
3963+
sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Package))
39643964
res := solveT(ctx, t, gwc, sr)
39653965
_, err := res.SingleRef()
39663966
assert.NilError(t, err)
@@ -4027,7 +4027,7 @@ func testLinuxLibArtirfacts(ctx context.Context, t *testing.T, cfg testLinuxConf
40274027
}
40284028

40294029
testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) {
4030-
sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Container))
4030+
sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Package))
40314031
res := solveT(ctx, t, gwc, sr)
40324032
_, err := res.SingleRef()
40334033
assert.NilError(t, err)
@@ -4071,7 +4071,7 @@ func testLinuxSymlinkArtifacts(ctx context.Context, t *testing.T, cfg testLinuxC
40714071
}
40724072

40734073
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
4074-
sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Container))
4074+
sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(cfg.Target.Package))
40754075
res := solveT(ctx, t, client, sr)
40764076
_, err := res.SingleRef()
40774077
assert.NilError(t, err)
@@ -4323,7 +4323,7 @@ func testLinuxPackageTestsFail(ctx context.Context, t *testing.T, cfg testLinuxC
43234323
}
43244324

43254325
t.Run("package", testForTarget(cfg.Target.Package))
4326-
t.Run("container", testForTarget(cfg.Target.Container))
4326+
t.Run("container", testForTarget(cfg.Target.Package))
43274327
})
43284328

43294329
t.Run("positive test", func(t *testing.T) {

test/multiple_artifacts_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ func testEmptyArtifacts(ctx context.Context, t *testing.T, targetCfg targetConfi
3131
t.Run("primary", func(t *testing.T) {
3232
t.Parallel()
3333
testEnv.RunTest(ctx, t, func(ctx context.Context, gwc gwclient.Client) {
34-
sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(targetCfg.Container))
34+
sr := newSolveRequest(withSpec(ctx, t, spec), withBuildTarget(targetCfg.Package))
3535
solveT(ctx, t, gwc, sr)
3636
})
3737
})
3838
}
3939

4040
// testArtifactsAtSpecLevel tests that artifacts defined in spec.artifacts are built and tested.
4141
func testArtifactsAtSpecLevel(ctx context.Context, t *testing.T, targetCfg targetConfig) {
42-
vals := strings.Split(targetCfg.Container, "/")
42+
vals := strings.Split(targetCfg.Package, "/")
4343
primaryTarget := vals[0]
4444

4545
spec := &dalec.Spec{
@@ -86,7 +86,7 @@ func testArtifactsAtSpecLevel(ctx context.Context, t *testing.T, targetCfg targe
8686
// testMultipleArtifacts tests that a package with multiple artifacts defined in spec.target takes precedent over spec.artifacts
8787
func testTargetArtifactsTakePrecedence(ctx context.Context, t *testing.T, targetCfg targetConfig) {
8888
// get the target we want to test for
89-
vals := strings.Split(targetCfg.Container, "/")
89+
vals := strings.Split(targetCfg.Package, "/")
9090
primaryTarget := vals[0]
9191
// prevent primaryTarget from being the same as secondaryTarget or tertiaryTarget
9292
secondaryTarget := "mariner2"

0 commit comments

Comments
 (0)