mirror of
https://github.com/linka-cloud/d2vm.git
synced 2025-12-14 15:03:12 +00:00
add grub-efi support
* tests: increase timeout * ci: split e2e tests Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
@@ -29,19 +29,22 @@ import (
|
||||
"go.linka.cloud/d2vm/pkg/exec"
|
||||
)
|
||||
|
||||
func testConfig(t *testing.T, ctx context.Context, img string, config Config) {
|
||||
func testConfig(t *testing.T, ctx context.Context, name, img string, config Config, luks, grubBIOS, grubEFI bool) {
|
||||
require.NoError(t, docker.Pull(ctx, img))
|
||||
tmpPath := filepath.Join(os.TempDir(), "d2vm-tests", strings.NewReplacer(":", "-", ".", "-").Replace(img))
|
||||
tmpPath := filepath.Join(os.TempDir(), "d2vm-tests", strings.NewReplacer(":", "-", ".", "-").Replace(name))
|
||||
require.NoError(t, os.MkdirAll(tmpPath, 0755))
|
||||
defer os.RemoveAll(tmpPath)
|
||||
logrus.Infof("inspecting image %s", img)
|
||||
r, err := FetchDockerImageOSRelease(ctx, img, tmpPath)
|
||||
r, err := FetchDockerImageOSRelease(ctx, img)
|
||||
require.NoError(t, err)
|
||||
defer docker.Remove(ctx, img)
|
||||
d, err := NewDockerfile(r, img, "root", "", false, false)
|
||||
if !r.SupportsLUKS() && luks {
|
||||
t.Skipf("LUKS not supported for %s", r.Version)
|
||||
}
|
||||
d, err := NewDockerfile(r, img, "root", "", luks, grubBIOS, grubEFI)
|
||||
require.NoError(t, err)
|
||||
logrus.Infof("docker image based on %s", d.Release.Name)
|
||||
p := filepath.Join(tmpPath, docker.FormatImgName(img))
|
||||
p := filepath.Join(tmpPath, docker.FormatImgName(name))
|
||||
dir := filepath.Dir(p)
|
||||
f, err := os.Create(p)
|
||||
require.NoError(t, err)
|
||||
@@ -51,6 +54,10 @@ func testConfig(t *testing.T, ctx context.Context, img string, config Config) {
|
||||
logrus.Infof("building kernel enabled image")
|
||||
require.NoError(t, docker.Build(ctx, imgUUID, p, dir))
|
||||
defer docker.Remove(ctx, imgUUID)
|
||||
// we don't need to test the kernel location if grub is enabled
|
||||
if grubBIOS || grubEFI {
|
||||
return
|
||||
}
|
||||
require.NoError(t, docker.RunAndRemove(ctx, imgUUID, "test", "-f", config.Kernel))
|
||||
require.NoError(t, docker.RunAndRemove(ctx, imgUUID, "test", "-f", config.Initrd))
|
||||
}
|
||||
@@ -116,13 +123,35 @@ func TestConfig(t *testing.T) {
|
||||
}
|
||||
exec.SetDebug(true)
|
||||
|
||||
names := []string{"luks", "grub-bios", "grub-efi"}
|
||||
bools := []bool{false, true}
|
||||
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.image, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
testConfig(t, ctx, test.image, test.config)
|
||||
for _, luks := range bools {
|
||||
for _, grubBIOS := range bools {
|
||||
for _, grubEFI := range bools {
|
||||
luks := luks
|
||||
grubBIOS := grubBIOS
|
||||
grubEFI := grubEFI
|
||||
n := []string{test.image}
|
||||
for i, v := range []bool{luks, grubBIOS, grubEFI} {
|
||||
if v {
|
||||
n = append(n, names[i])
|
||||
}
|
||||
}
|
||||
name := strings.Join(n, "-")
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
testConfig(t, ctx, name, test.image, test.config, luks, grubBIOS, grubEFI)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user