From 56d1607f72149dbbc4fc2338a45781d8fcea8c99 Mon Sep 17 00:00:00 2001 From: Dmitri Dolguikh Date: Wed, 12 Aug 2026 11:32:15 +0200 Subject: [PATCH] added mage + targets for integration tests + updated github workflow Signed-off-by: Dmitri Dolguikh --- .github/workflows/golang-test-linux.yml | 9 ++-- go.mod | 1 + go.sum | 2 + magefiles/magefile.go | 12 +++++ magefiles/test.go | 67 +++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 magefiles/magefile.go create mode 100644 magefiles/test.go diff --git a/.github/workflows/golang-test-linux.yml b/.github/workflows/golang-test-linux.yml index 0af506bba..9a74dfa9b 100644 --- a/.github/workflows/golang-test-linux.yml +++ b/.github/workflows/golang-test-linux.yml @@ -729,6 +729,11 @@ jobs: - name: Install modules run: go mod tidy + - name: Run Mage + uses: magefile/mage-action@v4 + with: + install-only: true + - name: check git status run: git --no-pager diff --exit-code @@ -737,9 +742,7 @@ jobs: CGO_ENABLED=1 GOARCH=${{ matrix.arch }} \ NETBIRD_STORE_ENGINE=${{ matrix.store }} \ CI=true \ - go test -tags=integration -coverprofile=coverage.txt \ - -exec 'sudo --preserve-env=CI,NETBIRD_STORE_ENGINE' \ - -timeout 20m ./management/server/http/... + mage integrationtest:all -gotestflags="-coverprofile=coverage.txt" - name: Upload coverage reports to Codecov if: matrix.arch == 'amd64' diff --git a/go.mod b/go.mod index c014796ca..f51b4ff66 100644 --- a/go.mod +++ b/go.mod @@ -252,6 +252,7 @@ require ( github.com/lib/pq v1.12.3 // indirect github.com/libdns/libdns v0.2.2 // indirect github.com/lufia/plan9stats v0.0.0-20240513124658-fba389f38bae // indirect + github.com/magefile/mage v1.17.2 // indirect github.com/magiconair/properties v1.8.10 // indirect github.com/mailru/easyjson v0.9.0 // indirect github.com/mattermost/xml-roundtrip-validator v0.1.0 // indirect diff --git a/go.sum b/go.sum index f754b11d6..0fac5c449 100644 --- a/go.sum +++ b/go.sum @@ -415,6 +415,8 @@ github.com/lrh3321/ipset-go v0.0.0-20250619021614-54a0a98ace81 h1:J56rFEfUTFT9j9 github.com/lrh3321/ipset-go v0.0.0-20250619021614-54a0a98ace81/go.mod h1:RD8ML/YdXctQ7qbcizZkw5mZ6l8Ogrl1dodBzVJduwI= github.com/lufia/plan9stats v0.0.0-20240513124658-fba389f38bae h1:dIZY4ULFcto4tAFlj1FYZl8ztUZ13bdq+PLY+NOfbyI= github.com/lufia/plan9stats v0.0.0-20240513124658-fba389f38bae/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k= +github.com/magefile/mage v1.17.2 h1:fyXVu1eadI8Ap1HCCNgEhJ5McIWiYhLR8uol64ZZc40= +github.com/magefile/mage v1.17.2/go.mod h1:Yj51kqllmsgFpvvSzgrZPK9WtluG3kUhFaBUVLo4feA= github.com/magiconair/properties v1.8.10 h1:s31yESBquKXCV9a/ScB3ESkOjUYYv+X0rg8SYxI99mE= github.com/magiconair/properties v1.8.10/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ= diff --git a/magefiles/magefile.go b/magefiles/magefile.go new file mode 100644 index 000000000..a1dc3c5f1 --- /dev/null +++ b/magefiles/magefile.go @@ -0,0 +1,12 @@ +//go:build mage + +//mage:multiline + +// Set the general description you want to have displayed with mage -l here. +package main + +// mg contains helpful utility functions, like Deps + +// Default target to run when none is specified +// If not set, running mage will list available targets +//var Default = Integrationtest.All diff --git a/magefiles/test.go b/magefiles/test.go new file mode 100644 index 000000000..5a8d7e936 --- /dev/null +++ b/magefiles/test.go @@ -0,0 +1,67 @@ +//go:build mage + +package main + +import ( + "errors" + "strings" + + "github.com/magefile/mage/mg" + "github.com/magefile/mage/sh" +) + +var defaultcli = []string{"test", "-tags=integration", "-timeout=20m"} + +type Integrationtest mg.Namespace + +func (i Integrationtest) All(gotestflags *string) error { + var errs []error + if err := i.Api(gotestflags); err != nil { + errs = append(errs, err) + } + if err := i.NmapDb(gotestflags); err != nil { + errs = append(errs, err) + } + if len(errs) > 0 { + return errors.Join(errs...) + } + return nil +} + +func (Integrationtest) NmapDb(gotestflags *string) error { + cli := defaultcli + if gotestflags != nil { + cli = append(cli, strings.Split(*gotestflags, " ")...) + } + cli = append(cli, "./integration_tests/management/network_map_db/...") + + return sh.RunV("go", cli...) +} + +func (Integrationtest) NmapDbPostgres(gotestflags *string) error { + cli := defaultcli + if gotestflags != nil { + cli = append(cli, strings.Split(*gotestflags, " ")...) + } + cli = append(cli, "./integration_tests/management/network_map_db/...") + + return sh.RunWithV(map[string]string{"NETBIRD_STORE_ENGINE": "postgres"}, "go", cli...) +} + +func (Integrationtest) NmapDbSqlite(gotestflags *string) error { + cli := defaultcli + if gotestflags != nil { + cli = append(cli, strings.Split(*gotestflags, " ")...) + } + cli = append(cli, "./integration_tests/management/network_map_db/...") + return sh.RunWithV(map[string]string{"NETBIRD_STORE_ENGINE": "sqlite"}, "go", cli...) +} + +func (Integrationtest) Api(gotestflags *string) error { + cli := defaultcli + if gotestflags != nil { + cli = append(cli, strings.Split(*gotestflags, " ")...) + } + cli = append(cli, "./management/server/http/...") + return sh.RunV("go", cli...) +}