-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
134 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package onmetal_image_test | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onmetal/onmetal-image" | ||
"github.com/onmetal/onmetal-image/oci/image" | ||
"github.com/onmetal/onmetal-image/oci/imageutil" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Image", func() { | ||
var ( | ||
ctx context.Context | ||
|
||
config Config | ||
kernelData, initramfsData, rootfsData []byte | ||
|
||
configLayer, kernelLayer, initramfsLayer, rootfsLayer image.Layer | ||
img image.Image | ||
) | ||
|
||
BeforeEach(func() { | ||
var cancel context.CancelFunc | ||
ctx, cancel = context.WithCancel(context.Background()) | ||
DeferCleanup(cancel) | ||
|
||
config = Config{} | ||
kernelData = []byte("kernel") | ||
initramfsData = []byte("initramfs") | ||
rootfsData = []byte("rootfs") | ||
|
||
c, err := imageutil.JSONValueLayer(config, imageutil.WithMediaType(ConfigMediaType)) | ||
Expect(err).NotTo(HaveOccurred()) | ||
configLayer = c | ||
kernelLayer = imageutil.BytesLayer(kernelData, imageutil.WithMediaType(KernelLayerMediaType)) | ||
initramfsLayer = imageutil.BytesLayer(initramfsData, imageutil.WithMediaType(InitRAMFSLayerMediaType)) | ||
rootfsLayer = imageutil.BytesLayer(rootfsData, imageutil.WithMediaType(RootFSLayerMediaType)) | ||
|
||
i, err := imageutil.NewBuilder(configLayer). | ||
Layers(kernelLayer, initramfsLayer, rootfsLayer). | ||
Complete() | ||
Expect(err).NotTo(HaveOccurred()) | ||
img = i | ||
}) | ||
|
||
Describe("ResolveImage", func() { | ||
It("should correctly resolve the image", func() { | ||
By("resolving the image") | ||
res, err := ResolveImage(ctx, img) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("inspecting the config") | ||
Expect(res.Config).To(Equal(config)) | ||
|
||
By("inspecting the layers") | ||
Expect(imageutil.ReadLayerContent(ctx, res.Kernel)).To(Equal(kernelData)) | ||
Expect(imageutil.ReadLayerContent(ctx, res.RootFS)).To(Equal(rootfsData)) | ||
Expect(imageutil.ReadLayerContent(ctx, res.InitRAMFs)).To(Equal(initramfsData)) | ||
}) | ||
|
||
It("should error if the image contains invalid layers", func() { | ||
By("creating an image with an additional invalid layer") | ||
invalidLayer := imageutil.BytesLayer([]byte("invalid")) | ||
img, err := imageutil.NewBuilder(configLayer). | ||
Layers(kernelLayer, initramfsLayer, rootfsLayer, invalidLayer). | ||
Complete() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("resolving the invalid image") | ||
_, err = ResolveImage(ctx, img) | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
|
||
It("should error if the image is missing layers", func() { | ||
By("creating an image with the kernel layer missing") | ||
img, err := imageutil.NewBuilder(configLayer). | ||
Layers(initramfsLayer, rootfsLayer). | ||
Complete() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("resolving the invalid image") | ||
_, err = ResolveImage(ctx, img) | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package onmetal_image_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestOnmetalImage(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "OnmetalImage Suite") | ||
} |