|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +package imagecustomizerlib |
| 5 | + |
| 6 | +import ( |
| 7 | + "os" |
| 8 | + "path/filepath" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "github.com/microsoft/azure-linux-image-tools/toolkit/tools/imagecustomizerapi" |
| 12 | + "github.com/stretchr/testify/assert" |
| 13 | +) |
| 14 | + |
| 15 | +func TestCustomizeImageUbuntuUnsupportedAPIs(t *testing.T) { |
| 16 | + for _, baseImageInfo := range baseImageUbuntuAll { |
| 17 | + t.Run(baseImageInfo.Name, func(t *testing.T) { |
| 18 | + testCustomizeImageUbuntuUnsupportedAPIsHelper(t, baseImageInfo) |
| 19 | + }) |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +func testCustomizeImageUbuntuUnsupportedAPIsHelper(t *testing.T, baseImageInfo testBaseImageInfo) { |
| 24 | + baseImage := checkSkipForCustomizeImage(t, baseImageInfo) |
| 25 | + |
| 26 | + testTmpDir := filepath.Join(tmpDir, "TestCustomizeImageUbuntuUnsupportedAPIs_"+baseImageInfo.Name) |
| 27 | + defer os.RemoveAll(testTmpDir) |
| 28 | + |
| 29 | + buildDir := filepath.Join(testTmpDir, "build") |
| 30 | + |
| 31 | + options := ImageCustomizerOptions{ |
| 32 | + BuildDir: buildDir, |
| 33 | + InputImageFile: baseImage, |
| 34 | + OutputImageFile: "./out/image.vhdx", |
| 35 | + OutputImageFormat: "vhdx", |
| 36 | + UseBaseImageRpmRepos: true, |
| 37 | + PreviewFeatures: baseImageInfo.PreviewFeatures, |
| 38 | + } |
| 39 | + |
| 40 | + config := &imagecustomizerapi.Config{ |
| 41 | + OS: &imagecustomizerapi.OS{}, |
| 42 | + } |
| 43 | + |
| 44 | + config.OS.BootLoader.ResetType = imagecustomizerapi.ResetBootLoaderTypeHard |
| 45 | + |
| 46 | + err := CustomizeImage(t.Context(), testTmpDir, config, options) |
| 47 | + assert.ErrorIs(t, err, ErrUbuntuUnsupportedBootloaderHardReset) |
| 48 | + assert.ErrorIs(t, err, ErrUnsupportedDistroApi) |
| 49 | + |
| 50 | + config.OS.BootLoader.ResetType = imagecustomizerapi.ResetBootLoaderTypeDefault |
| 51 | + options.UseBaseImageRpmRepos = false |
| 52 | + |
| 53 | + err = CustomizeImage(t.Context(), testTmpDir, config, options) |
| 54 | + assert.ErrorIs(t, err, ErrUbuntuUnsupportedDisableBaseImageRepos) |
| 55 | + assert.ErrorIs(t, err, ErrUnsupportedDistroApi) |
| 56 | +} |
0 commit comments