Skip to content

Commit 6ee8a2c

Browse files
committed
NeoEden: add initial tests
The idea is to get rid of the escript and write tests using go testing infra. This is a first step twoards that goal. The main principales are 1. DRY and KISS. 2. Tests are grouped together (only smoke at the moment) 3. Tests broken into different categories based on what they test, like just EVE, or App or Network (for now just simple eve tests are ported) 5. Setup once and use in multiple tests, for example setup an app once and share it between (no-destructive) tests. Signed-off-by: Shahriyar Jalayeri <[email protected]>
1 parent 7d7df1b commit 6ee8a2c

File tree

13 files changed

+3303
-2
lines changed

13 files changed

+3303
-2
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ unit-test:
9999
$(EMPTY_DRIVE).%:
100100
qemu-img create -f $* $@ $(EMPTY_DRIVE_SIZE)
101101

102-
build-tests: build testbin
102+
build-tests: build testbin neo-testbin
103103
install: build
104104
CGO_ENABLED=0 go install .
105105

@@ -127,6 +127,9 @@ $(LINUXKIT): $(BUILDTOOLS_DIR)
127127
testbin: config
128128
make -C tests DEBUG=$(DEBUG) ARCH=$(ARCH) OS=$(OS) WORKDIR=$(WORKDIR) build
129129

130+
neo-testbin:
131+
make -C neo-eden/tests DEBUG=$(DEBUG) ARCH=$(ARCH) OS=$(OS) WORKDIR=$(WORKDIR) build
132+
130133
config: build
131134
ifeq ($(OS), $(HOSTOS))
132135
$(LOCALBIN) config add default -v $(DEBUG) $(CONFIG)
@@ -145,7 +148,7 @@ stop: build
145148
dist: build-tests
146149
tar cvzf dist/eden_dist.tgz dist/bin dist/scripts dist/tests dist/*.txt
147150

148-
.PHONY: all clean test build build-tests tests-export config setup stop testbin dist
151+
.PHONY: all clean test build build-tests tests-export config setup stop testbin neo-testbin dist
149152

150153
push-multi-arch-eserver:
151154
@echo "Build and $(DOCKER_TARGET) eserver image $(ESERVER_TAG):$(ESERVER_VERSION)"

neo-eden/tests/Makefile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
DEBUG ?= "debug"
2+
TESTS ?= $(wildcard */Makefile)
3+
4+
DOCKER_TARGET ?= load
5+
DOCKER_PLATFORM ?= $(shell uname -s | tr '[A-Z]' '[a-z]')/$(subst aarch64,arm64,$(subst x86_64,amd64,$(shell uname -m)))
6+
7+
# HOSTARCH is the host architecture
8+
# ARCH is the target architecture
9+
# we need to keep track of them separately
10+
HOSTARCH ?= $(shell uname -m)
11+
HOSTOS ?= $(shell uname -s | tr A-Z a-z)
12+
13+
# canonicalized names for host architecture
14+
override HOSTARCH := $(subst aarch64,arm64,$(subst x86_64,amd64,$(HOSTARCH)))
15+
16+
# unless otherwise set, I am building for my own architecture, i.e. not cross-compiling
17+
# and for my OS
18+
ARCH ?= $(HOSTARCH)
19+
OS ?= $(HOSTOS)
20+
21+
WORKDIR ?= $(CURDIR)/../dist
22+
23+
gotestsum:
24+
go get -d gotest.tools/gotestsum
25+
26+
#test: $(TESTS:=_test)
27+
test: gotestsum
28+
gotestsum --jsonfile $(WORKDIR)/results.json --junitfile $(WORKDIR)/results.xml --raw-command -- go tool test2json -t ../eden test workflow -v debug
29+
30+
build: $(TESTS:=_build)
31+
setup: $(TESTS:=_setup)
32+
clean: $(TESTS:=_clean)
33+
build-docker: $(TESTS:=_build_docker)
34+
35+
.PHONY: test build setup clean all
36+
37+
%_test: % %_build %_setup
38+
#make -C $$(dirname $<) DEBUG=$(DEBUG) ARCH=$(ARCH) OS=$(OS) WORKDIR=$(WORKDIR) test
39+
40+
%_build: %
41+
make -C $$(dirname $<) DEBUG=$(DEBUG) ARCH=$(ARCH) OS=$(OS) WORKDIR=$(WORKDIR) build
42+
43+
%_setup: %
44+
make -C $$(dirname $<) DEBUG=$(DEBUG) ARCH=$(ARCH) OS=$(OS) WORKDIR=$(WORKDIR) setup
45+
46+
%_clean: %
47+
make -C $$(dirname $<) DEBUG=$(DEBUG) ARCH=$(ARCH) OS=$(OS) WORKDIR=$(WORKDIR) clean
48+
49+
%_build_docker: %
50+
@grep ^build-docker: $< && make -C $$(dirname $<) DEBUG=$(DEBUG) ARCH=$(ARCH) OS=$(OS) WORKDIR=$(WORKDIR) DOCKER_TARGET=$(DOCKER_TARGET) DOCKER_PLATFORM=$(DOCKER_PLATFORM) build-docker; exit 0

neo-eden/tests/README.md

Whitespace-only changes.

neo-eden/tests/app/.gitkeep

Whitespace-only changes.

neo-eden/tests/eve/Makefile

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
DEBUG ?= "debug"
2+
3+
# HOSTARCH is the host architecture
4+
# ARCH is the target architecture
5+
# we need to keep track of them separately
6+
HOSTARCH ?= $(shell uname -m)
7+
HOSTOS ?= $(shell uname -s | tr A-Z a-z)
8+
9+
# canonicalized names for host architecture
10+
override HOSTARCH := $(subst aarch64,arm64,$(subst x86_64,amd64,$(HOSTARCH)))
11+
12+
# unless otherwise set, I am building for my own architecture, i.e. not cross-compiling
13+
# and for my OS
14+
ARCH ?= $(HOSTARCH)
15+
OS ?= $(HOSTOS)
16+
17+
# canonicalized names for target architecture
18+
override ARCH := $(subst aarch64,arm64,$(subst x86_64,amd64,$(ARCH)))
19+
20+
WORKDIR ?= $(CURDIR)/../../../dist
21+
TESTDIR := tests/$(shell basename $(CURDIR))
22+
BINDIR := $(WORKDIR)/bin
23+
DATADIR := $(WORKDIR)/$(TESTDIR)/
24+
TESTNAME := neoeden.eve
25+
TESTBIN := $(TESTNAME).testsuite
26+
LOCALBIN := $(BINDIR)/$(TESTBIN)-$(OS)-$(ARCH)
27+
LOCALTESTBIN := $(TESTBIN)-$(OS)-$(ARCH)
28+
.DEFAULT_GOAL := help
29+
30+
clean:
31+
rm -rf $(LOCALTESTBIN) $(BINDIR)/$(TESTBIN) $(CURDIR)/$(TESTBIN) $(BINDIR)/$(TESTBIN)
32+
33+
$(BINDIR):
34+
mkdir -p $@
35+
$(DATADIR):
36+
mkdir -p $@
37+
38+
test:
39+
EDEN_CONFIG="default" $(LOCALBIN) test $(CURDIR) -v $(DEBUG)
40+
41+
build: setup
42+
43+
testbin: $(TESTBIN)
44+
$(LOCALTESTBIN): $(BINDIR) *.go
45+
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go test -c -ldflags "-s -w" -o $@ *.go
46+
47+
$(TESTBIN): $(LOCALTESTBIN)
48+
ln -sf $(LOCALTESTBIN) $(CURDIR)/$(TESTBIN)
49+
50+
setup: testbin $(BINDIR) $(DATADIR)
51+
mv $(LOCALTESTBIN) $(CURDIR)/$(TESTBIN) $(BINDIR)
52+
53+
debug:
54+
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go test -c -gcflags "all=-N -l" -o $@ *.go
55+
dlv dap --listen=:12345 --headless=true exec ./debug -- -test.v
56+
57+
.PHONY: test build setup clean all testbin debug
58+
59+
help:
60+
@echo "EDEN is the harness for testing EVE and ADAM"
61+
@echo
62+
@echo "This Makefile automates commons tasks of EDEN testing"
63+
@echo
64+
@echo "Commonly used maintenance and development targets:"
65+
@echo " build build test-binary (OS and ARCH options supported, for ex. OS=linux ARCH=arm64)"
66+
@echo " setup setup of test environment"
67+
@echo " test run tests"
68+
@echo " clean cleanup of test harness"
69+
@echo
70+
@echo "You need install requirements for EVE (look at https://github.com/lf-edge/eve#install-dependencies)."
71+
@echo "You need access to docker socket and installed qemu packages."

neo-eden/tests/eve/go.mod

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
module eve_test
2+
3+
go 1.22.5
4+
5+
replace github.com/lf-edge/eden => ../../../
6+
7+
replace github.com/lf-edge/eden/sdn/vm => ../../../sdn/vm
8+
9+
replace github.com/lf-edge/eve/libs/depgraph => github.com/lf-edge/eve/libs/depgraph v0.0.0-20220711144346-0659e3b03496
10+
11+
require (
12+
github.com/bloomberg/go-testgroup v1.1.1
13+
github.com/lf-edge/eden v0.0.0-00010101000000-000000000000
14+
github.com/sirupsen/logrus v1.9.3
15+
)
16+
17+
require (
18+
cloud.google.com/go/compute v1.21.0 // indirect
19+
cloud.google.com/go/compute/metadata v0.2.3 // indirect
20+
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
21+
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 // indirect
22+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
23+
github.com/Insei/rolgo v0.0.2 // indirect
24+
github.com/Microsoft/go-winio v0.6.1 // indirect
25+
github.com/Microsoft/hcsshim v0.11.4 // indirect
26+
github.com/amitbet/vncproxy v0.0.0-20200118084310-ea8f9b510913 // indirect
27+
github.com/beorn7/perks v1.0.1 // indirect
28+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
29+
github.com/containerd/cgroups v1.1.0 // indirect
30+
github.com/containerd/containerd v1.7.11 // indirect
31+
github.com/containerd/continuity v0.4.2 // indirect
32+
github.com/containerd/fifo v1.1.0 // indirect
33+
github.com/containerd/log v0.1.0 // indirect
34+
github.com/containerd/stargz-snapshotter/estargz v0.14.3 // indirect
35+
github.com/containerd/ttrpc v1.2.2 // indirect
36+
github.com/containerd/typeurl/v2 v2.1.1 // indirect
37+
github.com/davecgh/go-spew v1.1.1 // indirect
38+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
39+
github.com/docker/cli v24.0.6+incompatible // indirect
40+
github.com/docker/distribution v2.8.2+incompatible // indirect
41+
github.com/docker/docker v24.0.9+incompatible // indirect
42+
github.com/docker/docker-credential-helpers v0.7.0 // indirect
43+
github.com/docker/go-connections v0.4.0 // indirect
44+
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
45+
github.com/docker/go-metrics v0.0.1 // indirect
46+
github.com/docker/go-units v0.5.0 // indirect
47+
github.com/dustin/go-humanize v1.0.0 // indirect
48+
github.com/fatih/color v1.15.0 // indirect
49+
github.com/felixge/httpsnoop v1.0.3 // indirect
50+
github.com/fsnotify/fsnotify v1.6.0 // indirect
51+
github.com/go-logr/logr v1.2.4 // indirect
52+
github.com/go-logr/stdr v1.2.2 // indirect
53+
github.com/go-redis/redis/v9 v9.0.0-beta.1 // indirect
54+
github.com/go-resty/resty/v2 v2.7.0 // indirect
55+
github.com/gogo/protobuf v1.3.2 // indirect
56+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
57+
github.com/golang/protobuf v1.5.3 // indirect
58+
github.com/google/go-cmp v0.5.9 // indirect
59+
github.com/google/go-containerregistry v0.19.1 // indirect
60+
github.com/google/s2a-go v0.1.4 // indirect
61+
github.com/google/uuid v1.3.0 // indirect
62+
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
63+
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
64+
github.com/gorilla/mux v1.8.0 // indirect
65+
github.com/hashicorp/hcl v1.0.0 // indirect
66+
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
67+
github.com/klauspost/compress v1.16.5 // indirect
68+
github.com/lf-edge/eden/eserver v0.0.0-20220711180217-6e2bfa9c3f67 // indirect
69+
github.com/lf-edge/eden/sdn/vm v0.0.0-00010101000000-000000000000 // indirect
70+
github.com/lf-edge/edge-containers v0.0.0-20240207093504-5dfda0619b80 // indirect
71+
github.com/lf-edge/eve-api/go v0.0.0-20240816135418-f858514b03a3 // indirect
72+
github.com/lf-edge/eve/libs/depgraph v0.0.0-20220711144346-0659e3b03496 // indirect
73+
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 // indirect
74+
github.com/magiconair/properties v1.8.6 // indirect
75+
github.com/mattn/go-colorable v0.1.13 // indirect
76+
github.com/mattn/go-isatty v0.0.19 // indirect
77+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
78+
github.com/mcuadros/go-lookup v0.0.0-20200831155250-80f87a4fa5ee // indirect
79+
github.com/mitchellh/go-homedir v1.1.0 // indirect
80+
github.com/mitchellh/mapstructure v1.5.0 // indirect
81+
github.com/moby/locker v1.0.1 // indirect
82+
github.com/moby/patternmatcher v0.6.0 // indirect
83+
github.com/moby/sys/mountinfo v0.6.2 // indirect
84+
github.com/moby/sys/sequential v0.5.0 // indirect
85+
github.com/moby/sys/signal v0.7.0 // indirect
86+
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
87+
github.com/morikuni/aec v1.0.0 // indirect
88+
github.com/nerd2/gexto v0.0.0-20190529073929-39468ec063f6 // indirect
89+
github.com/opencontainers/go-digest v1.0.0 // indirect
90+
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
91+
github.com/opencontainers/runc v1.1.12 // indirect
92+
github.com/opencontainers/runtime-spec v1.1.0-rc.1 // indirect
93+
github.com/opencontainers/selinux v1.11.0 // indirect
94+
github.com/packethost/packngo v0.25.0 // indirect
95+
github.com/pelletier/go-toml v1.9.5 // indirect
96+
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
97+
github.com/pkg/errors v0.9.1 // indirect
98+
github.com/pmezard/go-difflib v1.0.0 // indirect
99+
github.com/prometheus/client_golang v1.14.0 // indirect
100+
github.com/prometheus/client_model v0.3.0 // indirect
101+
github.com/prometheus/common v0.37.0 // indirect
102+
github.com/prometheus/procfs v0.8.0 // indirect
103+
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
104+
github.com/spf13/afero v1.9.2 // indirect
105+
github.com/spf13/cast v1.5.0 // indirect
106+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
107+
github.com/spf13/pflag v1.0.5 // indirect
108+
github.com/spf13/viper v1.12.0 // indirect
109+
github.com/stretchr/testify v1.8.4 // indirect
110+
github.com/subosito/gotenv v1.4.0 // indirect
111+
github.com/tmc/scp v0.0.0-20170824174625-f7b48647feef // indirect
112+
github.com/vbatts/tar-split v0.11.3 // indirect
113+
go.opencensus.io v0.24.0 // indirect
114+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
115+
go.opentelemetry.io/otel v1.19.0 // indirect
116+
go.opentelemetry.io/otel/metric v1.19.0 // indirect
117+
go.opentelemetry.io/otel/trace v1.19.0 // indirect
118+
golang.org/x/crypto v0.21.0 // indirect
119+
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91 // indirect
120+
golang.org/x/mod v0.11.0 // indirect
121+
golang.org/x/net v0.23.0 // indirect
122+
golang.org/x/oauth2 v0.10.0 // indirect
123+
golang.org/x/sync v0.3.0 // indirect
124+
golang.org/x/sys v0.18.0 // indirect
125+
golang.org/x/term v0.18.0 // indirect
126+
golang.org/x/text v0.14.0 // indirect
127+
golang.org/x/tools v0.10.0 // indirect
128+
google.golang.org/api v0.126.0 // indirect
129+
google.golang.org/appengine v1.6.7 // indirect
130+
google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect
131+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
132+
google.golang.org/grpc v1.58.3 // indirect
133+
google.golang.org/protobuf v1.33.0 // indirect
134+
gopkg.in/ini.v1 v1.66.6 // indirect
135+
gopkg.in/yaml.v2 v2.4.0 // indirect
136+
gopkg.in/yaml.v3 v3.0.1 // indirect
137+
oras.land/oras-go v1.2.4 // indirect
138+
)

0 commit comments

Comments
 (0)