Skip to content

Commit

Permalink
Add Makefile target to run unit tests in enclave.
Browse files Browse the repository at this point in the history
  • Loading branch information
NullHypothesis committed Nov 3, 2024
1 parent 885a7a3 commit d0658f9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
cmd/veil/veil
cover.html
cover.out
veil.tar
veil.eif
39 changes: 37 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ prog = veil
prog_dir = cmd/veil
godeps = go.mod go.sum $(shell find cmd internal -name "*.go" -type f)

image_tag := $(prog)
image_tar := $(prog).tar
image_eif := $(prog).eif

cover_out = cover.out
cover_html = cover.html

Expand All @@ -17,6 +21,37 @@ lint: $(godeps)
test: $(godeps)
go test -race -cover ./...

$(image_tar): $(godeps) docker/Dockerfile-unit-test
@echo "Building $(image_tar)..."
@docker run --volume $(PWD):/workspace \
gcr.io/kaniko-project/executor:v1.9.2 \
--dockerfile docker/Dockerfile-unit-test \
--reproducible \
--no-push \
--verbosity warn \
--tarPath $(image_tar) \
--destination $(image_tag) \
--custom-platform linux/amd64

$(image_eif): $(image_tar)
@echo "Building $(image_eif)..."
@docker load --quiet --input $<
@nitro-cli build-enclave \
--docker-uri $(image_tag) \
--output-file $(image_eif)

.PHONY: enclave-test
enclave-test: $(godeps) $(image_eif)
@echo "Running enclave tests..."
@nitro-cli terminate-enclave \
--all
@nitro-cli run-enclave \
--enclave-name veil-unit-tests \
--eif-path $(image_eif) \
--attach-console \
--cpu-count 2 \
--memory 3500

.PHONY: coverage
coverage: $(cover_html)
open $(cover_html)
Expand All @@ -39,5 +74,5 @@ $(prog): $(godeps)
.PHONY: clean
clean:
rm -f $(prog_dir)/$(prog)
rm -f $(cover_out)
rm -f $(cover_html)
rm -f $(cover_out) $(cover_html)
rm -f $(image_tar) $(image_eif)
14 changes: 14 additions & 0 deletions docker/Dockerfile-unit-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.23

WORKDIR /app

RUN mkdir cmd/ internal/ vendor/
COPY cmd/ ./cmd/
COPY internal/ ./internal/
COPY vendor/ ./vendor/
COPY Makefile go.mod go.sum ./
COPY scripts/run-unit-tests.sh ./

RUN go mod download

CMD ["/app/run-tests.sh"]
12 changes: 12 additions & 0 deletions scripts/run-unit-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

cd /app
# Needed for Go's build cache.
export HOME=/app
# Needed because otherwise we're getting:
# fork/exec /tmp/go-build1885828642/b001/cmd.test: permission denied
mkdir -p /app/tmp
export TMPDIR=/app/tmp

echo "Running Go unit tests..."
$(which go) test -cover ./...

0 comments on commit d0658f9

Please sign in to comment.