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 2, 2024
1 parent 885a7a3 commit 6fa0742
Show file tree
Hide file tree
Showing 4 changed files with 66 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
15 changes: 15 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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 run-tests.sh ./

RUN go mod download

CMD ["/app/run-tests.sh"]
# CMD ["/usr/local/go/bin/go", "test", "-v", "./..."]
38 changes: 36 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,36 @@ lint: $(godeps)
test: $(godeps)
go test -race -cover ./...

$(image_tar): Dockerfile.test
@echo "Building $(image_tar)..."
@docker run --volume $(PWD):/workspace \
gcr.io/kaniko-project/executor:v1.9.2 \
--dockerfile Dockerfile.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 -i $<
@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 3356

.PHONY: coverage
coverage: $(cover_html)
open $(cover_html)
Expand All @@ -39,5 +73,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)
13 changes: 13 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/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 6fa0742

Please sign in to comment.