Skip to content

Commit 6803283

Browse files
committed
Add unit tests for the ToPack and PackLLB functions
Add unit tests for the functions in hops/package.go file. These functions are the backbone for the transformation of hops (i.e. bunnyfile input) to the final instructions passed to buildkit. Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk>
1 parent 157c751 commit 6803283

File tree

3 files changed

+996
-7
lines changed

3 files changed

+996
-7
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ test: unittest
118118

119119
## unittest Run all unit tests
120120
.PHONY: unittest
121-
unittest: test_validate test_parse test_llb test_unikraft test_generic
121+
unittest: test_validate test_parse test_pack test_llb test_unikraft test_generic
122122

123123
## test_llb Run unit tests for hops package regarding LLB state creations
124124
test_llb:
@@ -144,6 +144,12 @@ test_parse:
144144
@GOFLAGS=$(TEST_FLAGS) $(GO) test $(TEST_OPTS) ./hops -run TestParse -v
145145
@echo " "
146146

147+
## test_pack Run unit tests for hops package regarding packaging from bunnyfile
148+
test_pack:
149+
@echo "Unit testing for bunnyfile-based image building"
150+
@GOFLAGS=$(TEST_FLAGS) $(GO) test $(TEST_OPTS) ./hops -run TestPack -v
151+
@echo " "
152+
147153
## test_validate Run unit tests for hops package regarding input validation
148154
test_validate:
149155
@echo "Unit testing in input validation"

hops/package.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func ToPack(h *Hops, buildContext string) (*PackInstructions, error) {
155155
// 1) The rootfs is empty and we do not have to do anything
156156
// 2) The rootfs is a raw type rootfs
157157
// The value that will guide us is the From field
158-
if h.Rootfs.From != "scratch" {
158+
if h.Rootfs.From != "scratch" && h.Rootfs.From != "" {
159159
// We have a raw rootfs
160160
if !framework.SupportsRootfsType("raw") {
161161
return nil, fmt.Errorf("%s does not support raw rootfs type", framework.Name())
@@ -189,13 +189,10 @@ func ToPack(h *Hops, buildContext string) (*PackInstructions, error) {
189189
if err != nil {
190190
return nil, err
191191
}
192-
switch framework.GetRootfsType() {
193-
case "initrd":
192+
if framework.GetRootfsType() == "initrd" {
194193
instr.Annots["com.urunc.unikernel.initrd"] = DefaultRootfsPath
195-
case "raw":
194+
} else if framework.GetRootfsType() == "raw" {
196195
instr.Annots["com.urunc.unikernel.mountRootfs"] = "true"
197-
default:
198-
return nil, fmt.Errorf("Unexpected RootfsType value from framework")
199196
}
200197

201198
// Switch the base to the rootfs's From image

0 commit comments

Comments
 (0)