Browse Source

integ: Use go 1.20 integration cover support

go 1.20 now has built-in merging of cover profiles, using GOCOVERDIR and
the `go tool covdata` command.
This feature requires running integration tests as "normal" binaries
instead of tests, so I've updated the server6_test accordingly

cf https://go.dev/blog/integration-test-coverage

Signed-off-by: Anatole Denis <anatole@unverle.fr>
Anatole Denis 1 year ago
parent
commit
f97f9f36e8
3 changed files with 24 additions and 18 deletions
  1. 16 11
      .github/workflows/tests.yml
  2. 0 0
      integ/server6/leases-dhcpv6-test.txt
  3. 8 7
      integ/server6/server6.go

+ 16 - 11
.github/workflows/tests.yml

@@ -63,24 +63,29 @@ jobs:
           cd $GITHUB_WORKSPACE/src/github.com/${{ github.repository }}
           ./.ci/setup-integ.sh
       - name: run integ tests
+        env:
+          GOCOVERDIR: ${{github.workspace}}/.cover
         run: |
-          cd $GITHUB_WORKSPACE/src/github.com/${{ github.repository }}/integ
-          go get -v -t -tags=integration ./...
-          echo "" > "${GITHUB_WORKSPACE}"/coverage.txt
-          for d in $(go list -tags=integration ./...); do
-              go test -c -tags=integration -v -race -coverprofile=profile.out -covermode=atomic "${d}"
-              testbin="./$(basename $d).test"
+          mkdir $GOCOVERDIR
+          cd $GITHUB_WORKSPACE/src/github.com/${{ github.repository }}
+          go get -v -t -tags=integration ./integ/...
+          for d in integ/*; do
+              pushd "$d"
+              go build -tags=integration -race -cover -coverpkg=github.com/coredhcp/coredhcp/... .
+              testbin=$(basename $d)
+              test -x "${testbin}" || echo "::error file=${d}::missing binary for integration test ${d}"
               # only run it if it was built - i.e. if there are integ tests
-              test -x "${testbin}" && sudo "./${testbin}"
-              if [ -f profile.out ]; then
-                cat profile.out >> "${GITHUB_WORKSPACE}"/coverage.txt
-                rm profile.out
+              test -x "${testbin}" && sudo --preserve-env=GOCOVERDIR "./${testbin}"
+              if [ $? -ne 0 ]; then
+                echo "::error file=${d}::Execution of integration tests for ${d} failed"
               fi
+              popd
           done
+          go tool covdata textfmt -i=$GOCOVERDIR -o=coverage.txt
       - name: report coverage to codecov
         uses: codecov/codecov-action@v4
         with:
-          files: ${{github.workspace}}/coverage.txt
+          files: coverage.txt
           disable_search: true
           flags: integtests
           fail_ci_if_error: true

+ 0 - 0
integ/leases-dhcpv6-test.txt → integ/server6/leases-dhcpv6-test.txt


+ 8 - 7
integ/server6_test.go → integ/server6/server6.go

@@ -5,19 +5,17 @@
 //go:build integration
 // +build integration
 
-package e2e_test
+package main
 
 import (
 	"fmt"
 	"log"
 	"net"
 	"runtime"
-	"testing"
 
 	"github.com/insomniacslk/dhcp/dhcpv6"
 	"github.com/insomniacslk/dhcp/dhcpv6/client6"
 	"github.com/insomniacslk/dhcp/iana"
-	"github.com/stretchr/testify/require"
 	"github.com/vishvananda/netns"
 
 	"github.com/coredhcp/coredhcp/config"
@@ -103,8 +101,8 @@ func runClient6(nsName, iface string, modifiers ...dhcpv6.Modifier) error {
 	return cErr
 }
 
-// TestDora creates a server and attempts to connect to it
-func TestDora(t *testing.T) {
+// Create a server and run a DORA exchange with it
+func main() {
 	readyCh := make(chan struct{}, 1)
 	go runServer(readyCh,
 		"coredhcp-direct-upper",
@@ -118,11 +116,14 @@ func TestDora(t *testing.T) {
 	if err != nil {
 		panic(err)
 	}
-	require.NoError(t, runClient6(
+	err = runClient6(
 		"coredhcp-direct-lower", "cdhcp_cli",
 		dhcpv6.WithClientID(&dhcpv6.DUIDLL{
 			HWType:        iana.HWTypeEthernet,
 			LinkLayerAddr: mac,
 		}),
-	))
+	)
+	if err != nil {
+		panic(err)
+	}
 }