diff --git a/.codecov.yaml b/.codecov.yaml index 3a4c1246..2ccd95e6 100644 --- a/.codecov.yaml +++ b/.codecov.yaml @@ -1,5 +1,6 @@ --- ignore: +# Auto-generated files - pkg/proto/**/*.pb.go - pkg/signaling/k8s/apis/**/* - pkg/signaling/k8s/client/**/* diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0f07b4f2..09a93466 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -141,9 +141,9 @@ jobs: if: ${{ matrix.target_arch == matrix.host_arch && matrix.target_os == matrix.host_os && matrix.host_os == 'windows' }} run: make tests GINKGO_EXTRA_OPTS="--label-filter=!broken-on-windows" - - name: Run integration tests + - name: Run end-to-end tests if: ${{ matrix.target_arch == matrix.host_arch && matrix.target_os == matrix.host_os && matrix.host_os == 'linux' }} - run: sudo --preserve-env env "PATH=$PATH" make tests-integration + run: sudo --preserve-env env "PATH=$PATH" make tests-e2e - name: Upload logs an packet captures as artifacts if: ${{ always() && matrix.target_arch == matrix.host_arch && matrix.target_os == matrix.host_os && matrix.host_os == 'linux' }} diff --git a/.gitignore b/.gitignore index 4439e2cd..a50c25d2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ dist/ *.test *.out.* lcov.info -test/logs/ +test/e2e/logs/ diff --git a/Makefile b/Makefile index 6c6ca75e..3f0496b6 100644 --- a/Makefile +++ b/Makefile @@ -9,9 +9,9 @@ LDFLAGS = -X riasc.eu/wice/pkg/util/buildinfo.Version=$(shell git describe --tag -X riasc.eu/wice/pkg/util/buildinfo.Date=$(shell date -Iseconds) \ -X riasc.eu/wice/pkg/util/buildinfo.BuiltBy=Makefile \ -PKGS ?= ./cmd/... ./pkg/... +PKGS ?= ./cmd/... ./pkg/... ./test ifeq ($(GOOS),linux) - PKGS += ./test/... + PKGS += ./test/e2e/... endif GINKGO_OPTS = --compilers=2 \ @@ -34,9 +34,9 @@ wice: tests: ginkgo run $(GINKGO_OPTS) --coverprofile=coverprofile.out ./pkg/... -tests-integration: +tests-e2e: mkdir -p test/logs - ginkgo run $(GINKGO_OPTS) --output-dir=./test/logs --coverprofile=coverprofile_integration.out ./test + ginkgo run $(GINKGO_OPTS) --output-dir=./test/e2e/logs --coverprofile=coverprofile_integration.out ./test/e2e coverprofile_merged.out: $(shell find . -name "*.out" -type f) gocov-merger -o $@ $^ diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 15b24739..6316dda2 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -13,7 +13,7 @@ import ( "github.com/pion/ice/v2" "riasc.eu/wice/pkg/config" - "riasc.eu/wice/pkg/test" + "riasc.eu/wice/test" icex "riasc.eu/wice/pkg/feat/epdisc/ice" ) diff --git a/pkg/core/core_test.go b/pkg/core/core_test.go index cd63ddc9..3f629965 100644 --- a/pkg/core/core_test.go +++ b/pkg/core/core_test.go @@ -7,8 +7,8 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "riasc.eu/wice/pkg/test" "riasc.eu/wice/pkg/util" + "riasc.eu/wice/test" ) func TestSuite(t *testing.T) { diff --git a/pkg/crypto/crypto_test.go b/pkg/crypto/crypto_test.go index 48fb46de..f9ddd00f 100644 --- a/pkg/crypto/crypto_test.go +++ b/pkg/crypto/crypto_test.go @@ -6,7 +6,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "riasc.eu/wice/pkg/crypto" - "riasc.eu/wice/pkg/test" + "riasc.eu/wice/test" ) func TestSuite(t *testing.T) { diff --git a/pkg/crypto/types_test.go b/pkg/crypto/types_test.go index 53070233..de3d53d0 100644 --- a/pkg/crypto/types_test.go +++ b/pkg/crypto/types_test.go @@ -5,7 +5,7 @@ import ( "net" "riasc.eu/wice/pkg/crypto" - "riasc.eu/wice/pkg/test" + "riasc.eu/wice/test" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/pkg/device/device_test.go b/pkg/device/device_test.go index 2e48ff3d..f370e4a9 100644 --- a/pkg/device/device_test.go +++ b/pkg/device/device_test.go @@ -6,8 +6,8 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "riasc.eu/wice/pkg/test" "riasc.eu/wice/pkg/util" + "riasc.eu/wice/test" ) func TestSuite(t *testing.T) { diff --git a/pkg/feat/epdisc/ice/ice_test.go b/pkg/feat/epdisc/ice/ice_test.go index 4ad56d7a..c1297531 100644 --- a/pkg/feat/epdisc/ice/ice_test.go +++ b/pkg/feat/epdisc/ice/ice_test.go @@ -5,7 +5,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "riasc.eu/wice/pkg/test" + "riasc.eu/wice/test" ) func TestSuite(t *testing.T) { diff --git a/pkg/log/log_test.go b/pkg/log/log_test.go index 15f1d795..bb2fa268 100644 --- a/pkg/log/log_test.go +++ b/pkg/log/log_test.go @@ -25,6 +25,8 @@ func TestSuite(t *testing.T) { RunSpecs(t, "Logging Suite") } +// TODO: This test is currently broken on Windows dues: +// https://github.com/uber-go/zap/issues/621 var _ = Context("log", Label("broken-on-windows"), func() { var logger *zap.Logger var lvl zapcore.Level diff --git a/pkg/proto/proto_test.go b/pkg/proto/proto_test.go index ef0a4d45..953e6c62 100644 --- a/pkg/proto/proto_test.go +++ b/pkg/proto/proto_test.go @@ -5,7 +5,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "riasc.eu/wice/pkg/test" + "riasc.eu/wice/test" ) func TestSuite(t *testing.T) { diff --git a/pkg/proto/signaling/signaling_test.go b/pkg/proto/signaling/signaling_test.go index 00ce7021..4cac0359 100644 --- a/pkg/proto/signaling/signaling_test.go +++ b/pkg/proto/signaling/signaling_test.go @@ -6,7 +6,7 @@ import ( "google.golang.org/protobuf/proto" "riasc.eu/wice/pkg/crypto" - "riasc.eu/wice/pkg/test" + "riasc.eu/wice/test" protoepdisc "riasc.eu/wice/pkg/proto/feat/epdisc" signalingproto "riasc.eu/wice/pkg/proto/signaling" diff --git a/pkg/signaling/grpc/backend_test.go b/pkg/signaling/grpc/backend_test.go index 1ed83fb9..a4aa3cc1 100644 --- a/pkg/signaling/grpc/backend_test.go +++ b/pkg/signaling/grpc/backend_test.go @@ -8,7 +8,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "riasc.eu/wice/pkg/signaling/grpc" - "riasc.eu/wice/pkg/test" + "riasc.eu/wice/test" ) func TestSuite(t *testing.T) { diff --git a/pkg/signaling/inprocess/backend_test.go b/pkg/signaling/inprocess/backend_test.go index b8115e42..a04cd075 100644 --- a/pkg/signaling/inprocess/backend_test.go +++ b/pkg/signaling/inprocess/backend_test.go @@ -7,7 +7,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" _ "riasc.eu/wice/pkg/signaling/inprocess" - "riasc.eu/wice/pkg/test" + "riasc.eu/wice/test" ) func TestSuite(t *testing.T) { diff --git a/pkg/signaling/k8s/backend_test.go b/pkg/signaling/k8s/backend_test.go index 51135dbe..0b054f86 100644 --- a/pkg/signaling/k8s/backend_test.go +++ b/pkg/signaling/k8s/backend_test.go @@ -13,7 +13,7 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd/api" - "riasc.eu/wice/pkg/test" + "riasc.eu/wice/test" "sigs.k8s.io/controller-runtime/pkg/envtest" "sigs.k8s.io/controller-runtime/pkg/log" ) diff --git a/pkg/signaling/signaling_test.go b/pkg/signaling/signaling_test.go index 10560d6f..7fb776b6 100644 --- a/pkg/signaling/signaling_test.go +++ b/pkg/signaling/signaling_test.go @@ -5,7 +5,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "riasc.eu/wice/pkg/test" + "riasc.eu/wice/test" ) func TestSuite(t *testing.T) { diff --git a/pkg/util/json.go b/pkg/util/json.go new file mode 100644 index 00000000..f3898011 --- /dev/null +++ b/pkg/util/json.go @@ -0,0 +1,13 @@ +package util + +import "encoding/json" + +func ReIndentJSON(j []byte, prefix, indent string) ([]byte, error) { + u := map[string]any{} + + if err := json.Unmarshal(j, &u); err != nil { + return nil, err + } + + return json.MarshalIndent(u, prefix, indent) +} diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go index 4915a0de..f66929b2 100644 --- a/pkg/util/util_test.go +++ b/pkg/util/util_test.go @@ -6,8 +6,8 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "riasc.eu/wice/pkg/test" "riasc.eu/wice/pkg/util" + "riasc.eu/wice/test" ) func TestSuite(t *testing.T) { diff --git a/pkg/watcher/watcher_test.go b/pkg/watcher/watcher_test.go index 79a60e42..a391a558 100644 --- a/pkg/watcher/watcher_test.go +++ b/pkg/watcher/watcher_test.go @@ -14,10 +14,10 @@ import ( "riasc.eu/wice/pkg/core" "riasc.eu/wice/pkg/crypto" "riasc.eu/wice/pkg/device" - "riasc.eu/wice/pkg/test" "riasc.eu/wice/pkg/util" "riasc.eu/wice/pkg/watcher" "riasc.eu/wice/pkg/wg" + "riasc.eu/wice/test" ) func TestSuite(t *testing.T) { diff --git a/pkg/wg/wg_test.go b/pkg/wg/wg_test.go index 23f8caea..8f74ce8c 100644 --- a/pkg/wg/wg_test.go +++ b/pkg/wg/wg_test.go @@ -5,7 +5,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "riasc.eu/wice/pkg/test" + "riasc.eu/wice/test" ) func TestSuite(t *testing.T) { diff --git a/pkg/test/backend.go b/test/backend.go similarity index 100% rename from pkg/test/backend.go rename to test/backend.go diff --git a/test/nat_double_test.go b/test/e2e/nat_double_test.go similarity index 93% rename from test/nat_double_test.go rename to test/e2e/nat_double_test.go index 73dadb47..49e8291a 100644 --- a/test/nat_double_test.go +++ b/test/e2e/nat_double_test.go @@ -1,4 +1,4 @@ -package test_test +package e2e_test import ( "fmt" @@ -7,8 +7,8 @@ import ( . "github.com/onsi/gomega" g "github.com/stv0g/gont/pkg" gopt "github.com/stv0g/gont/pkg/options" - "riasc.eu/wice/test/nodes" - wopt "riasc.eu/wice/test/nodes/options/wg" + "riasc.eu/wice/test/e2e/nodes" + wopt "riasc.eu/wice/test/e2e/nodes/options/wg" ) /* Carrier Grade NAT setup with two relays and a single signaling server @@ -39,7 +39,7 @@ import ( * │ n1 │ │ n2 │ * └──────┘ └──────┘ */ -var _ = Context("nat double", func() { +var _ = Context("nat double: Carrier Grade NAT setup with two relays and a single signaling server", func() { var ( err error @@ -221,7 +221,7 @@ var _ = Context("nat double", func() { n.SignalingNodes = nodes.SignalingList{s1} }) - Context("2-nodes", func() { + Context("2-nodes: Two agents connected to lan1 and lan2", func() { JustBeforeEach(func() { n.Start() }) @@ -229,7 +229,7 @@ var _ = Context("nat double", func() { n.ConnectivityTests() }) - Context("3-nodes", func() { + Context("3-nodes: Additional agent connected to lan2", func() { JustBeforeEach(func() { AddAgent(3, lan2) @@ -239,7 +239,7 @@ var _ = Context("nat double", func() { n.ConnectivityTests() }) - Context("4-nodes", func() { + Context("4-nodes: Additional agent connected to wan2", func() { JustBeforeEach(func() { AddAgent(3, lan2) AddAgent(4, wan2) @@ -250,7 +250,7 @@ var _ = Context("nat double", func() { n.ConnectivityTests() }) - Context("5-nodes", func() { + Context("5-nodes: Additional agent connected to wan1", func() { JustBeforeEach(func() { AddAgent(3, lan2) AddAgent(4, wan2) diff --git a/test/nat_test.go b/test/e2e/nat_test.go similarity index 92% rename from test/nat_test.go rename to test/e2e/nat_test.go index df568742..728483c0 100644 --- a/test/nat_test.go +++ b/test/e2e/nat_test.go @@ -1,4 +1,4 @@ -package test_test +package e2e_test import ( "fmt" @@ -7,8 +7,8 @@ import ( . "github.com/onsi/gomega" g "github.com/stv0g/gont/pkg" gopt "github.com/stv0g/gont/pkg/options" - "riasc.eu/wice/test/nodes" - wopt "riasc.eu/wice/test/nodes/options/wg" + "riasc.eu/wice/test/e2e/nodes" + wopt "riasc.eu/wice/test/e2e/nodes/options/wg" ) /* Typical wide-area NAT setup @@ -40,7 +40,7 @@ import ( * │ n1 │ │ n2 │ │ (n3) │ * └──────┘ └──────┘ └──────┘ */ -var _ = Context("nat simple", func() { +var _ = Context("nat simple: Simple home-router NAT setup", func() { var ( err error @@ -141,7 +141,7 @@ var _ = Context("nat simple", func() { n.SignalingNodes = nodes.SignalingList{s1} }) - Context("2-nodes", func() { + Context("2-nodes: Two agents connected to lan1 & lan2", func() { JustBeforeEach(func() { n.Start() }) @@ -149,7 +149,7 @@ var _ = Context("nat simple", func() { n.ConnectivityTests() }) - Context("3-nodes", func() { + Context("3-nodes: Additional agent connected to lan2", func() { JustBeforeEach(func() { AddAgent(3, lan2) diff --git a/test/network_others_test.go b/test/e2e/network_others_test.go similarity index 88% rename from test/network_others_test.go rename to test/e2e/network_others_test.go index 38c7aec5..d1944775 100644 --- a/test/network_others_test.go +++ b/test/e2e/network_others_test.go @@ -1,6 +1,6 @@ //go:build !tracer -package test_test +package e2e_test type HandshakeTracer any diff --git a/test/network_test.go b/test/e2e/network_test.go similarity index 87% rename from test/network_test.go rename to test/e2e/network_test.go index 52250cca..74a9d0cd 100644 --- a/test/network_test.go +++ b/test/e2e/network_test.go @@ -1,4 +1,4 @@ -package test_test +package e2e_test import ( "context" @@ -6,7 +6,6 @@ import ( "math/rand" "os" "path/filepath" - "strings" "time" . "github.com/onsi/ginkgo/v2" @@ -16,9 +15,9 @@ import ( copt "github.com/stv0g/gont/pkg/options/capture" "go.uber.org/zap" - "riasc.eu/wice/pkg/test" "riasc.eu/wice/pkg/util" - "riasc.eu/wice/test/nodes" + "riasc.eu/wice/test" + "riasc.eu/wice/test/e2e/nodes" ) var ( @@ -157,10 +156,29 @@ func (n *Network) Close() { Expect(err).To(Succeed(), "Failed to close network; %s", err) n.StopHandshakeTracer() + n.WriteSpecReport() GinkgoWriter.ClearTeeWriters() } +func (n *Network) WriteSpecReport() { + report := CurrentSpecReport() + report.CapturedGinkgoWriterOutput = "" + + reportJSON, err := report.MarshalJSON() + Expect(err).To(Succeed(), "Failed to marshal report: %s", err) + + reportJSON, err = util.ReIndentJSON(reportJSON, "", " ") + Expect(err).To(Succeed(), "Failed to indent report: %s", err) + + reportFileName := filepath.Join(n.BasePath, "report.json") + reportFile, err := os.OpenFile(reportFileName, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) + Expect(err).To(Succeed(), "Failed to open report file: %s", err) + + _, err = reportFile.Write(reportJSON) + Expect(err).To(Succeed(), "Failed to write report: %s", err) +} + func (n *Network) ConnectivityTests() { It("", func() { By("Waiting until all peers are connected") @@ -182,9 +200,7 @@ func (n *Network) Init() { *n = Network{} n.Name = fmt.Sprintf("wice-%d", rand.Uint32()) - - name := GinkgoT().Name() - n.BasePath = filepath.Join(strings.Split(name, " ")...) + n.BasePath = filepath.Join(SpecName()...) n.BasePath = filepath.Join("logs", n.BasePath) logFilename := filepath.Join(n.BasePath, "test.log") diff --git a/test/network_tracer_test.go b/test/e2e/network_tracer_test.go similarity index 98% rename from test/network_tracer_test.go rename to test/e2e/network_tracer_test.go index 83f19b64..cd34c9be 100644 --- a/test/network_tracer_test.go +++ b/test/e2e/network_tracer_test.go @@ -1,6 +1,6 @@ //go:build tracer -package test_test +package e2e_test import ( "bytes" diff --git a/test/nodes/agent.go b/test/e2e/nodes/agent.go similarity index 100% rename from test/nodes/agent.go rename to test/e2e/nodes/agent.go diff --git a/test/nodes/agent_list.go b/test/e2e/nodes/agent_list.go similarity index 100% rename from test/nodes/agent_list.go rename to test/e2e/nodes/agent_list.go diff --git a/test/nodes/build.go b/test/e2e/nodes/build.go similarity index 91% rename from test/nodes/build.go rename to test/e2e/nodes/build.go index bc656ed3..bed997a4 100644 --- a/test/nodes/build.go +++ b/test/e2e/nodes/build.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/onsi/gomega/gexec" - "riasc.eu/wice/test" ) @@ -49,7 +48,7 @@ func BuildTestBinary(name string) (string, []any, error) { // Build a test binary if profiling is requested if len(profileFlags) > 0 { // Generate coverage for all wice packages - profileFlags["coverpkg"] = "../..." + profileFlags["coverpkg"] = "../../..." buildArgs = append(buildArgs, "-tags", "test") @@ -60,9 +59,9 @@ func BuildTestBinary(name string) (string, []any, error) { // We compile a dummy go test binary here which just // invokes main(), but is instrumented for profiling. - testBinaryPath, err = gexec.CompileTest("../cmd/wice", buildArgs...) + testBinaryPath, err = gexec.CompileTest("../../cmd/wice", buildArgs...) } else { - testBinaryPath, err = gexec.Build("../cmd/wice", buildArgs...) + testBinaryPath, err = gexec.Build("../../cmd/wice", buildArgs...) } } diff --git a/test/nodes/node.go b/test/e2e/nodes/node.go similarity index 100% rename from test/nodes/node.go rename to test/e2e/nodes/node.go diff --git a/test/nodes/options/agent.go b/test/e2e/nodes/options/agent.go similarity index 81% rename from test/nodes/options/agent.go rename to test/e2e/nodes/options/agent.go index 6ad4183f..0283bba2 100644 --- a/test/nodes/options/agent.go +++ b/test/e2e/nodes/options/agent.go @@ -1,7 +1,7 @@ package options import ( - "riasc.eu/wice/test/nodes" + "riasc.eu/wice/test/e2e/nodes" ) type ExtraArgs []any diff --git a/test/nodes/options/wg/interface.go b/test/e2e/nodes/options/wg/interface.go similarity index 98% rename from test/nodes/options/wg/interface.go rename to test/e2e/nodes/options/wg/interface.go index e06d30c4..67929bb4 100644 --- a/test/nodes/options/wg/interface.go +++ b/test/e2e/nodes/options/wg/interface.go @@ -7,7 +7,7 @@ import ( g "github.com/stv0g/gont/pkg" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" "riasc.eu/wice/pkg/crypto" - "riasc.eu/wice/test/nodes" + "riasc.eu/wice/test/e2e/nodes" ) type PrivateKey crypto.Key diff --git a/test/nodes/options/wg/peer.go b/test/e2e/nodes/options/wg/peer.go similarity index 98% rename from test/nodes/options/wg/peer.go rename to test/e2e/nodes/options/wg/peer.go index 36473ae1..74df43d8 100644 --- a/test/nodes/options/wg/peer.go +++ b/test/e2e/nodes/options/wg/peer.go @@ -7,7 +7,7 @@ import ( "golang.zx2c4.com/wireguard/wgctrl/wgtypes" "riasc.eu/wice/pkg/crypto" - "riasc.eu/wice/test/nodes" + "riasc.eu/wice/test/e2e/nodes" ) // PublicKey specifies the public key of this peer. PublicKey is a diff --git a/test/nodes/relay.go b/test/e2e/nodes/relay.go similarity index 100% rename from test/nodes/relay.go rename to test/e2e/nodes/relay.go diff --git a/test/nodes/relay_coturn.go b/test/e2e/nodes/relay_coturn.go similarity index 100% rename from test/nodes/relay_coturn.go rename to test/e2e/nodes/relay_coturn.go diff --git a/test/nodes/relay_list.go b/test/e2e/nodes/relay_list.go similarity index 100% rename from test/nodes/relay_list.go rename to test/e2e/nodes/relay_list.go diff --git a/test/nodes/signaling.go b/test/e2e/nodes/signaling.go similarity index 100% rename from test/nodes/signaling.go rename to test/e2e/nodes/signaling.go diff --git a/test/nodes/signaling_grpc.go b/test/e2e/nodes/signaling_grpc.go similarity index 100% rename from test/nodes/signaling_grpc.go rename to test/e2e/nodes/signaling_grpc.go diff --git a/test/nodes/signaling_list.go b/test/e2e/nodes/signaling_list.go similarity index 100% rename from test/nodes/signaling_list.go rename to test/e2e/nodes/signaling_list.go diff --git a/test/nodes/wg_interface.go b/test/e2e/nodes/wg_interface.go similarity index 100% rename from test/nodes/wg_interface.go rename to test/e2e/nodes/wg_interface.go diff --git a/test/nodes/wg_peer.go b/test/e2e/nodes/wg_peer.go similarity index 100% rename from test/nodes/wg_peer.go rename to test/e2e/nodes/wg_peer.go diff --git a/test/restart_test.go b/test/e2e/restart_test.go similarity index 78% rename from test/restart_test.go rename to test/e2e/restart_test.go index dbf2b237..ebf41f23 100644 --- a/test/restart_test.go +++ b/test/e2e/restart_test.go @@ -1,4 +1,4 @@ -package test_test +package e2e_test import ( "context" @@ -6,10 +6,11 @@ import ( "time" "riasc.eu/wice/pkg/crypto" + "riasc.eu/wice/pkg/proto" "riasc.eu/wice/pkg/util" "riasc.eu/wice/pkg/wg" - "riasc.eu/wice/test/nodes" - wopt "riasc.eu/wice/test/nodes/options/wg" + "riasc.eu/wice/test/e2e/nodes" + wopt "riasc.eu/wice/test/e2e/nodes/options/wg" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -37,7 +38,7 @@ import ( * └────┘ └────┘ * wice Agents */ -var _ = Context("restart", func() { +var _ = Context("restart: Restart ICE agents", func() { var ( err error n Network @@ -123,9 +124,7 @@ var _ = Context("restart", func() { ConnectivityTestCycle := func() { n.ConnectivityTests() - It("", func() { - By("Triggering restart") - + It("Triggering restart", func() { restart(gap) time.Sleep(gap) @@ -134,7 +133,7 @@ var _ = Context("restart", func() { n.ConnectivityTests() } - Context("quick", Ordered, func() { + Context("quick: Waiting 3 seconds", Ordered, func() { BeforeEach(func() { gap = 3 * time.Second }) @@ -142,7 +141,7 @@ var _ = Context("restart", func() { ConnectivityTestCycle() }) - Context("slow", Ordered, func() { + Context("slow: Waiting 10 seconds to trigger an ICE disconnect", Ordered, func() { BeforeEach(func() { gap = 10 * time.Second // > ICE failed/disconnected timeout (5s) }) @@ -151,7 +150,7 @@ var _ = Context("restart", func() { }) } - Context("agent", func() { + Context("agent: Restart agent", func() { RestartTest(func(gap time.Duration) { By("Stopping first agent") @@ -169,7 +168,7 @@ var _ = Context("restart", func() { }) }) - Context("addresses", Pending, func() { + Context("addresses: Change uplink IP address", Pending, func() { RestartTest(func(gap time.Duration) { i := n1.Interface("eth0") Expect(i).NotTo(BeNil(), "Failed to find agent interface") @@ -206,7 +205,7 @@ var _ = Context("restart", func() { }) }) - Context("link", Pending, func() { + Context("link: Bring uplink down and up", Pending, func() { RestartTest(func(gap time.Duration) { i := n1.Interface("eth0") Expect(i).NotTo(BeNil(), "Failed to find agent interface") @@ -227,36 +226,62 @@ var _ = Context("restart", func() { }) }) - Context("rpc", func() { + Context("peer-rpc: Restart peer via RPC", func() { RestartTest(func(gap time.Duration) { ctx := context.Background() - i := n1.WireGuardInterfaces[0] - p := i.Peers[0] - pk := (*crypto.Key)(&p.PublicKey) - By("Initiating restart via RPC") + i := n1.WireGuardInterfaces[0] + pk := (*crypto.Key)(&i.Peers[0].PublicKey) err = n1.Client.RestartPeer(ctx, i.Name, pk) Expect(err).To(Succeed(), "Failed to restart peer: %s", err) }) }) - Context("signaling", Pending, func() { + Context("agent-rpc: Restart agent via RPC", Pending, func() { RestartTest(func(gap time.Duration) { + ctx := context.Background() + + By("Initiating agent restart via RPC") + + _, err = n1.Client.Restart(ctx, &proto.Empty{}) + Expect(err).To(Succeed(), "Failed to restart peer: %s", err) + }) + }) + + Context("signaling: Restart signaling server", Pending, func() { + RestartTest(func(gap time.Duration) { + ctx := context.Background() + By("Stopping signaling server") err = s1.Stop() Expect(err).To(Succeed(), "Failed to stop signaling server") + By("Restarting peer") + + i := n1.WireGuardInterfaces[0] + pk := (*crypto.Key)(&i.Peers[0].PublicKey) + err = n1.Client.RestartPeer(ctx, i.Name, pk) + Expect(err).To(Succeed(), "Failed to restart peer: %s", err) + By("Waiting some time") time.Sleep(gap) - By("Re-starting signaling server again") + By("Starting signaling server again") err = s1.Start("", n.BasePath) Expect(err).To(Succeed(), "Failed to restart signaling server: %s", err) }) }) + + Context("private-key: Trigger recreation of peer by changing private-key of interface", func() { + RestartTest(func(gap time.Duration) { + By("Changing private-key") + + // i.Configuring + }) + }) }) diff --git a/test/simple_test.go b/test/e2e/simple_test.go similarity index 76% rename from test/simple_test.go rename to test/e2e/simple_test.go index e1913d16..3cf79ce8 100644 --- a/test/simple_test.go +++ b/test/e2e/simple_test.go @@ -1,13 +1,13 @@ -package test_test +package e2e_test import ( "fmt" "golang.org/x/sys/unix" "riasc.eu/wice/pkg/wg" - "riasc.eu/wice/test/nodes" - opt "riasc.eu/wice/test/nodes/options" - wopt "riasc.eu/wice/test/nodes/options/wg" + "riasc.eu/wice/test/e2e/nodes" + opt "riasc.eu/wice/test/e2e/nodes/options" + wopt "riasc.eu/wice/test/e2e/nodes/options/wg" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -37,7 +37,7 @@ import ( * └────┘ └────┘ └────┘ * wice Agents */ -var _ = Context("simple", Serial, func() { +var _ = Context("simple: Simple local-area switched topology with variable number of agents", Serial, func() { var ( err error n Network @@ -142,38 +142,38 @@ var _ = Context("simple", Serial, func() { ConnectivityTestsForAllCandidateTypes := func() { Context("candidate-types", func() { - Context("any", func() { - Context("ipv4", func() { + Context("any: Allow any candidate type", func() { + Context("ipv4: Allow IPv4 network only", func() { ConnectivityTestsWithExtraArgs("--ice-network-type", "udp4") }) - Context("ipv6", func() { + Context("ipv6: Allow IPv6 network only", func() { ConnectivityTestsWithExtraArgs("--ice-network-type", "udp6") }) }) - Context("host", func() { - Context("ipv4", func() { + Context("host: Allow only host candidates", func() { + Context("ipv4: Allow IPv4 network only", func() { ConnectivityTestsWithExtraArgs("--ice-candidate-type", "host", "--ice-network-type", "udp4") }) - Context("ipv6", func() { + Context("ipv6: Allow IPv6 network only", func() { ConnectivityTestsWithExtraArgs("--ice-candidate-type", "host", "--ice-network-type", "udp6") }) }) - Context("srflx", func() { - Context("ipv4", func() { + Context("srflx: Allow only server reflexive candidates", func() { + Context("ipv4: Allow IPv4 network only", func() { ConnectivityTestsWithExtraArgs("--ice-candidate-type", "srflx", "--ice-network-type", "udp4") }) - Context("ipv6", func() { + Context("ipv6: Allow IPv6 network only", func() { ConnectivityTestsWithExtraArgs("--ice-candidate-type", "srflx", "--ice-network-type", "udp6") }) }) - Context("relay", func() { - Context("ipv4", func() { + Context("relay: Allow only relay candidates", func() { + Context("ipv4: Allow IPv4 network only", func() { ConnectivityTestsWithExtraArgs("--ice-candidate-type", "relay", "--ice-network-type", "udp4") }) @@ -185,11 +185,11 @@ var _ = Context("simple", Serial, func() { }) } - Context("kernel", func() { + Context("kernel: Use kernel WireGuard interface", func() { ConnectivityTestsForAllCandidateTypes() }) - Context("userspace", func() { + Context("userspace: Use wireguard-go userspace interfaces", func() { BeforeEach(func() { n.WireGuardInterfaceOptions = append(n.WireGuardInterfaceOptions, wopt.WriteConfigFile(true), @@ -204,8 +204,8 @@ var _ = Context("simple", Serial, func() { ConnectivityTestsForAllCandidateTypes() }) - Context("filtered", func() { - Context("p2p", func() { + Context("filtered: Block WireGuard UDP traffic", func() { + Context("p2p: Between agents only", func() { BeforeEach(func() { // We are dropped packets between the ɯice nodes to force ICE using the relay n.AgentOptions = append(n.AgentOptions, @@ -225,7 +225,7 @@ var _ = Context("simple", Serial, func() { n.ConnectivityTests() }) - Context("all-udp", func() { + Context("all-udp: All UDP entirely", func() { BeforeEach(func() { n.AgentOptions = append(n.AgentOptions, gopt.Filter(g.FilterInput, @@ -239,4 +239,32 @@ var _ = Context("simple", Serial, func() { n.ConnectivityTests() }) }) + + Context("pdisc: Peer Discovery", Pending, Ordered, func() { + BeforeEach(OncePerOrdered, func() { + n.AgentOptions = append(n.AgentOptions, + opt.ExtraArgs{"--community", "hallo"}, + ) + + n.WireGuardInterfaceOptions = append(n.WireGuardInterfaceOptions, + wopt.NoPeers, + ) + + NumAgents = 3 + }) + + n.ConnectivityTests() + + It("", func() { + By("Check existing peers 2") + + n.AgentNodes.ForEachAgent(func(a *nodes.Agent) error { + out, _, err := a.Run("wg") + Expect(err).To(Succeed()) + + GinkgoWriter.Write(out) + return nil + }) + }) + }) }) diff --git a/test/single_test.go b/test/e2e/single_test.go similarity index 65% rename from test/single_test.go rename to test/e2e/single_test.go index 30a71f5e..77ac87cd 100644 --- a/test/single_test.go +++ b/test/e2e/single_test.go @@ -1,8 +1,8 @@ -package test_test +package e2e_test import ( "riasc.eu/wice/pkg/wg" - "riasc.eu/wice/test/nodes" + "riasc.eu/wice/test/e2e/nodes" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -10,7 +10,7 @@ import ( gopt "github.com/stv0g/gont/pkg/options" ) -var _ = Context("single", Pending, func() { +var _ = Context("single: A single node to test RPC and watcher", Pending, func() { var n Network BeforeEach(func() { @@ -43,17 +43,17 @@ var _ = Context("single", Pending, func() { n.AgentNodes = nodes.AgentList{n1} }) - Context("create", func() { - Context("kernel", func() { + Context("create: Create a new interface", func() { + Context("kernel: Kernel-space", func() { }) - Context("userspace", func() { + Context("userspace: User-space", func() { }) }) - Context("watcher", Ordered, func() { + Context("watcher: Watch for changes of WireGuard interfaces and peers", Ordered, func() { It("detects a new interface", func() { }) @@ -79,15 +79,19 @@ var _ = Context("single", Pending, func() { }) }) - Context("host-sync", func() { + Context("hsync: /etc/hosts synchronization", func() { }) - Context("route-sync", func() { + Context("rtsync: Route synchronization", func() { }) - Context("config-sync", func() { + Context("cfgsync: Config file synchronization", func() { + + }) + + Context("autocfg: Auto-configuration of missing interface parameters", func() { }) }) diff --git a/test/suite_test.go b/test/e2e/suite_test.go similarity index 59% rename from test/suite_test.go rename to test/e2e/suite_test.go index a8408b77..4e91e7e9 100644 --- a/test/suite_test.go +++ b/test/e2e/suite_test.go @@ -1,8 +1,9 @@ -package test_test +package e2e_test import ( "flag" "math/rand" + "strings" "testing" "time" @@ -12,6 +13,7 @@ import ( "github.com/onsi/gomega/gexec" "riasc.eu/wice/pkg/util" + "github.com/onsi/ginkgo/v2/reporters" "github.com/onsi/ginkgo/v2/types" ) @@ -33,7 +35,6 @@ func TestSuite(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "E2E Test Suite", types.ReporterConfig{ - JSONReport: "logs/report.json", SlowSpecThreshold: 1 * time.Minute, }) } @@ -45,3 +46,36 @@ var _ = BeforeSuite(func() { DeferCleanup(gexec.CleanupBuildArtifacts) }) + +var _ = ReportAfterSuite("Write report", func(r Report) { + r.SpecReports = nil + reporters.GenerateJSONReport(r, "logs/report.json") +}) + +func SpecName() []string { + sr := CurrentSpecReport() + + normalize := func(s string) ([]string, bool) { + p := strings.SplitN(s, ":", 2) + if len(p) != 2 { + return []string{}, false + } + + ps := strings.Split(strings.ToLower(p[0]), " ") + + return ps, true + } + + sn := []string{} + for _, txt := range sr.ContainerHierarchyTexts { + if n, ok := normalize(txt); ok { + sn = append(sn, n...) + } + } + + if n, ok := normalize(sr.LeafNodeText); ok { + sn = append(sn, n...) + } + + return sn +} diff --git a/pkg/test/log.go b/test/log.go similarity index 100% rename from pkg/test/log.go rename to test/log.go diff --git a/pkg/test/matchers.go b/test/matchers.go similarity index 100% rename from pkg/test/matchers.go rename to test/matchers.go diff --git a/pkg/test/test.go b/test/test.go similarity index 100% rename from pkg/test/test.go rename to test/test.go diff --git a/test/suite_norace.go b/test/test_norace.go similarity index 100% rename from test/suite_norace.go rename to test/test_norace.go diff --git a/test/suite_race.go b/test/test_race.go similarity index 100% rename from test/suite_race.go rename to test/test_race.go diff --git a/pkg/test/test_test.go b/test/test_test.go similarity index 97% rename from pkg/test/test_test.go rename to test/test_test.go index 3ce8a767..b1a56a6e 100644 --- a/pkg/test/test_test.go +++ b/test/test_test.go @@ -6,7 +6,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "riasc.eu/wice/pkg/test" + "riasc.eu/wice/test" ) func TestSuite(t *testing.T) {