Skip to content

Commit fd7520d

Browse files
willie-yaocpuguy83
authored andcommitted
Fix version matching test and add GoVersion field
Signed-off-by: William Yao <[email protected]>
1 parent 635b33c commit fd7520d

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

test/linux_target_test.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"encoding/json"
99
"errors"
1010
"fmt"
11+
"go/version"
1112
"io"
1213
"io/fs"
1314
"os"
@@ -31,8 +32,6 @@ import (
3132
"github.com/project-dalec/dalec/frontend"
3233
"github.com/project-dalec/dalec/frontend/pkg/bkfs"
3334
"github.com/project-dalec/dalec/targets"
34-
"github.com/project-dalec/dalec/targets/linux/deb/ubuntu"
35-
"github.com/project-dalec/dalec/targets/linux/rpm/azlinux"
3635
"github.com/project-dalec/dalec/test/testenv"
3736
"golang.org/x/exp/maps"
3837
"gotest.tools/v3/assert"
@@ -98,9 +97,10 @@ type testLinuxConfig struct {
9897
Units string
9998
Targets string
10099
}
101-
Libdir string
102-
Worker workerConfig
103-
Release OSRelease
100+
Libdir string
101+
Worker workerConfig
102+
Release OSRelease
103+
GoVersion string
104104

105105
Platforms []ocispecs.Platform
106106
PackageOutputPath func(spec *dalec.Spec, platform ocispecs.Platform) string
@@ -2274,23 +2274,20 @@ func True(t interface{}, value bool, msgAndArgs ...interface{}) bool {
22742274
t.Parallel()
22752275
ctx := startTestSpan(baseCtx, t)
22762276

2277-
// Skip on distros with older Go versions that can't handle toolchain downloads
2278-
// This test uses golang.org/x/[email protected] which may require Go 1.24+
2279-
// focal and mariner2 have Go < 1.22 and network is disabled during builds
2280-
skip.If(t, testConfig.Target.Key == azlinux.Mariner2TargetKey || testConfig.Target.Key == ubuntu.FocalDefaultTargetKey,
2281-
"Test requires Go 1.22+ for automatic toolchain management")
2277+
// Skip on distros with Go versions below 1.21 that can't handle automatic toolchain management
2278+
skip.If(t, testConfig.GoVersion == "" || version.Compare("go"+testConfig.GoVersion, "go1.21") < 0,
2279+
"Test requires Go 1.21+ for automatic toolchain management")
22822280

22832281
// Start with go.mod and go.work both at go 1.18
2284-
// Use a replace directive that may bump go.mod version
22852282
// Verify that go.work stays in sync with go.mod
22862283
pg := dalec.ProgressGroup("Setup test context")
22872284
contextSt := llb.Scratch().
2288-
File(llb.Mkfile("/go.mod", 0644, []byte("module example.com/test\n\ngo 1.18\n\nrequire golang.org/x/crypto v0.30.0\n")), pg).
2285+
File(llb.Mkfile("/go.mod", 0644, []byte("module example.com/test\n\ngo 1.18\n\nrequire go.etcd.io/etcd/client/v3 v3.5.0\n")), pg).
22892286
File(llb.Mkfile("/go.work", 0644, []byte("go 1.18\n\nuse .\n")), pg).
22902287
File(llb.Mkfile("/main.go", 0644, []byte(`package main
22912288
import (
22922289
"fmt"
2293-
_ "golang.org/x/crypto/bcrypt"
2290+
_ "go.etcd.io/etcd/client/v3"
22942291
)
22952292
func main() {
22962293
fmt.Println("hello")
@@ -2315,8 +2312,8 @@ func main() {
23152312
Gomod: &dalec.GeneratorGomod{
23162313
Edits: &dalec.GomodEdits{
23172314
Replace: []dalec.GomodReplace{
2318-
// This may cause go.mod version to be bumped depending on the Go toolchain
2319-
{Original: "golang.org/x/crypto", Update: "golang.org/x/[email protected]"},
2315+
// v3.5.14 requires go 1.21, which will bump go.mod from 1.18 to 1.21
2316+
{Original: "go.etcd.io/etcd/client/v3", Update: "go.etcd.io/etcd/client/[email protected]"},
23202317
},
23212318
},
23222319
},
@@ -2331,8 +2328,8 @@ func main() {
23312328
},
23322329
Build: dalec.ArtifactBuild{
23332330
Steps: []dalec.BuildStep{
2334-
{Command: "grep -F 'replace golang.org/x/crypto' ./src/go.mod"},
2335-
{Command: "grep -F 'golang.org/x/crypto v0.45.0' ./src/go.mod"},
2331+
{Command: "grep -F 'replace go.etcd.io/etcd/client/v3' ./src/go.mod"},
2332+
{Command: "grep -F 'go.etcd.io/etcd/client/v3 v3.5.14' ./src/go.mod"},
23362333
// Verify go.work exists
23372334
{Command: "test -f ./src/go.work"},
23382335
// Verify the go versions in go.mod and go.work match exactly

test/target_almalinux_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func TestAlmalinux9(t *testing.T) {
4545
ID: "almalinux",
4646
VersionID: "9",
4747
},
48+
GoVersion: "1.25",
4849
Platforms: []ocispecs.Platform{
4950
{OS: "linux", Architecture: "amd64"},
5051
{OS: "linux", Architecture: "arm64"},
@@ -90,6 +91,7 @@ func TestAlmalinux8(t *testing.T) {
9091
ID: "almalinux",
9192
VersionID: "8",
9293
},
94+
GoVersion: "1.25",
9395
Platforms: []ocispecs.Platform{
9496
{OS: "linux", Architecture: "amd64"},
9597
{OS: "linux", Architecture: "arm64"},

test/target_azlinux_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func TestMariner2(t *testing.T) {
7070
ID: "mariner",
7171
VersionID: "2.0",
7272
},
73+
GoVersion: "1.22",
7374
Platforms: []ocispecs.Platform{
7475
{OS: "linux", Architecture: "amd64"},
7576
{OS: "linux", Architecture: "arm64"},
@@ -113,6 +114,7 @@ func TestAzlinux3(t *testing.T) {
113114
ID: "azurelinux",
114115
VersionID: "3.0",
115116
},
117+
GoVersion: "1.25",
116118
Platforms: []ocispecs.Platform{
117119
{OS: "linux", Architecture: "amd64"},
118120
{OS: "linux", Architecture: "arm64"},

test/target_debian_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func TestTrixie(t *testing.T) {
1616
testConf := debLinuxTestConfigFor(
1717
debian.TrixieDefaultTargetKey,
1818
debian.TrixieConfig,
19+
withGoVersion("1.24"),
1920
withPackageOverride("rust", "rust-all"),
2021
withPackageOverride("bazel", "bazel-bootstrap"),
2122
)
@@ -31,6 +32,7 @@ func TestBookworm(t *testing.T) {
3132
testConf := debLinuxTestConfigFor(
3233
debian.BookwormDefaultTargetKey,
3334
debian.BookwormConfig,
35+
withGoVersion("1.19"),
3436
withPackageOverride("rust", "rust-all"),
3537
withPackageOverride("bazel", "bazel-bootstrap"),
3638
)
@@ -46,6 +48,7 @@ func TestBullseye(t *testing.T) {
4648
testConf := debLinuxTestConfigFor(
4749
debian.BullseyeDefaultTargetKey,
4850
debian.BullseyeConfig,
51+
withGoVersion("1.19"),
4952
withPackageOverride("golang", "golang-1.19"),
5053
withPackageOverride("rust", "cargo-web"),
5154
withPackageOverride("bazel", noPackageAvailable),

test/target_rockylinux_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func TestRockylinux9(t *testing.T) {
4545
ID: "rocky",
4646
VersionID: "9",
4747
},
48+
GoVersion: "1.25",
4849
Platforms: []ocispecs.Platform{
4950
{OS: "linux", Architecture: "amd64"},
5051
{OS: "linux", Architecture: "arm64"},
@@ -90,6 +91,7 @@ func TestRockylinux8(t *testing.T) {
9091
ID: "rocky",
9192
VersionID: "8",
9293
},
94+
GoVersion: "1.25",
9395
Platforms: []ocispecs.Platform{
9496
{OS: "linux", Architecture: "amd64"},
9597
{OS: "linux", Architecture: "arm64"},

test/target_ubuntu_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ func withPackageOverride(oldPkg, newPkg string) func(cfg *testLinuxConfig) {
2323
}
2424
}
2525

26+
func withGoVersion(version string) func(cfg *testLinuxConfig) {
27+
return func(cfg *testLinuxConfig) {
28+
cfg.GoVersion = version
29+
}
30+
}
31+
2632
func debLinuxTestConfigFor(targetKey string, cfg *distro.Config, opts ...func(*testLinuxConfig)) testLinuxConfig {
2733
var sysextTarget string
2834
if cfg.SysextSupported {
@@ -154,6 +160,7 @@ func TestJammy(t *testing.T) {
154160

155161
ctx := startTestSpan(baseCtx, t)
156162
testConf := debLinuxTestConfigFor(ubuntu.JammyDefaultTargetKey, ubuntu.JammyConfig,
163+
withGoVersion("1.18"),
157164
withPackageOverride("rust", "rust-all"),
158165
withPackageOverride("bazel", noPackageAvailable),
159166
withPackageOverride("python", "python3 python3-pip"),
@@ -168,6 +175,7 @@ func TestNoble(t *testing.T) {
168175

169176
ctx := startTestSpan(baseCtx, t)
170177
testConf := debLinuxTestConfigFor(ubuntu.NobleDefaultTargetKey, ubuntu.NobleConfig,
178+
withGoVersion("1.22"),
171179
withPackageOverride("rust", "rust-all"),
172180
withPackageOverride("bazel", "bazel-bootstrap"),
173181
)
@@ -180,6 +188,7 @@ func TestFocal(t *testing.T) {
180188

181189
ctx := startTestSpan(baseCtx, t)
182190
testConf := debLinuxTestConfigFor(ubuntu.FocalDefaultTargetKey, ubuntu.FocalConfig,
191+
withGoVersion("1.22"),
183192
withPackageOverride("golang", "golang-1.22"),
184193
withPackageOverride("rust", "rust-all"),
185194
withPackageOverride("bazel", noPackageAvailable),
@@ -194,6 +203,7 @@ func TestBionic(t *testing.T) {
194203

195204
ctx := startTestSpan(baseCtx, t)
196205
testConf := debLinuxTestConfigFor(ubuntu.BionicDefaultTargetKey, ubuntu.BionicConfig,
206+
withGoVersion("1.18"),
197207
withPackageOverride("golang", "golang-1.18"),
198208
withPackageOverride("rust", "rust-all"),
199209
withPackageOverride("bazel", noPackageAvailable),

0 commit comments

Comments
 (0)