diff --git a/Makefile b/Makefile index eeac280..c5a2d88 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ build: dev: lint test build test: - @go test -coverprofile=coverage.out ./... + @go test -short -coverprofile=coverage.out ./... test_integration: test_integration_cli test_integration_derp test_integration_oidc test_integration_general @@ -31,36 +31,40 @@ test_integration_cli: docker network create headscale-test || true docker run -t --rm \ --network headscale-test \ + -v ~/.cache/hs-integration-go:/go \ -v $$PWD:$$PWD -w $$PWD \ -v /var/run/docker.sock:/var/run/docker.sock golang:1 \ - go test -failfast -tags integration_cli,integration -timeout 30m -count=1 ./... + go test -failfast -timeout 30m -count=1 -run IntegrationCLI ./... test_integration_derp: docker network rm $$(docker network ls --filter name=headscale --quiet) || true docker network create headscale-test || true docker run -t --rm \ --network headscale-test \ + -v ~/.cache/hs-integration-go:/go \ -v $$PWD:$$PWD -w $$PWD \ -v /var/run/docker.sock:/var/run/docker.sock golang:1 \ - go test -failfast -tags integration_derp,integration -timeout 30m -count=1 ./... + go test -failfast -timeout 30m -count=1 -run IntegrationDERP ./... test_integration_general: docker network rm $$(docker network ls --filter name=headscale --quiet) || true docker network create headscale-test || true docker run -t --rm \ --network headscale-test \ + -v ~/.cache/hs-integration-go:/go \ -v $$PWD:$$PWD -w $$PWD \ -v /var/run/docker.sock:/var/run/docker.sock golang:1 \ - go test -failfast -tags integration_general,integration -timeout 30m -count=1 ./... + go test -failfast -timeout 30m -count=1 -run IntegrationGeneral ./... test_integration_oidc: docker network rm $$(docker network ls --filter name=headscale --quiet) || true docker network create headscale-test || true docker run -t --rm \ --network headscale-test \ + -v ~/.cache/hs-integration-go:/go \ -v $$PWD:$$PWD -w $$PWD \ -v /var/run/docker.sock:/var/run/docker.sock golang:1 \ - go test -failfast -tags integration_oidc,integration -timeout 30m -count=1 ./... + go test -failfast -timeout 30m -count=1 -run IntegrationOIDC ./... coverprofile_func: go tool cover -func=coverage.out diff --git a/flake.nix b/flake.nix index f7d0c66..6775e9c 100644 --- a/flake.nix +++ b/flake.nix @@ -26,6 +26,9 @@ version = headscaleVersion; src = pkgs.lib.cleanSource self; + # Only run unit tests when testing a build + checkFlags = ["-short"]; + # When updating go.mod or go.sum, a new sha will need to be calculated, # update this if you have a mismatch after doing a change to thos files. vendorSha256 = "sha256-DosFCSiQ5FURbIrt4NcPGkExc84t2MGMqe9XLxNHdIM="; diff --git a/integration_cli_test.go b/integration_cli_test.go index 0f5d69a..ee6a9e1 100644 --- a/integration_cli_test.go +++ b/integration_cli_test.go @@ -1,5 +1,4 @@ -//go:build integration_cli - +//nolint package headscale import ( @@ -28,7 +27,11 @@ type IntegrationCLITestSuite struct { env []string } -func TestCLIIntegrationTestSuite(t *testing.T) { +func TestIntegrationCLITestSuite(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration tests due to short flag") + } + s := new(IntegrationCLITestSuite) suite.Run(t, s) diff --git a/integration_common_test.go b/integration_common_test.go index 9fe435d..a165886 100644 --- a/integration_common_test.go +++ b/integration_common_test.go @@ -1,5 +1,4 @@ -//go:build integration - +//nolint package headscale import ( @@ -328,7 +327,6 @@ func GetEnvBool(key string) (bool, error) { func GetFirstOrCreateNetwork(pool *dockertest.Pool, name string) (dockertest.Network, error) { networks, err := pool.NetworksByName(name) if err != nil || len(networks) == 0 { - if _, err := pool.CreateNetwork(name); err == nil { // Create does not give us an updated version of the resource, so we need to // get it again. diff --git a/integration_embedded_derp_test.go b/integration_embedded_derp_test.go index c83f610..5bd6dee 100644 --- a/integration_embedded_derp_test.go +++ b/integration_embedded_derp_test.go @@ -1,5 +1,4 @@ -//go:build integration_derp - +//nolint package headscale import ( @@ -17,13 +16,12 @@ import ( "testing" "time" + "github.com/ccding/go-stun/stun" v1 "github.com/juanfont/headscale/gen/go/headscale/v1" "github.com/ory/dockertest/v3" "github.com/ory/dockertest/v3/docker" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - - "github.com/ccding/go-stun/stun" ) const ( @@ -46,7 +44,11 @@ type IntegrationDERPTestSuite struct { joinWaitGroup sync.WaitGroup } -func TestDERPIntegrationTestSuite(t *testing.T) { +func TestIntegrationDERPTestSuite(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration tests due to short flag") + } + saveLogs, err := GetEnvBool("HEADSCALE_INTEGRATION_SAVE_LOG") if err != nil { saveLogs = false @@ -120,7 +122,6 @@ func (s *IntegrationDERPTestSuite) SetupSuite() { } headscaleOptions := &dockertest.RunOptions{ - Name: headscaleDerpHostname, Mounts: []string{ fmt.Sprintf( diff --git a/integration_general_test.go b/integration_general_test.go index 5b5abf0..52bfddd 100644 --- a/integration_general_test.go +++ b/integration_general_test.go @@ -1,5 +1,4 @@ -//go:build integration_general - +//nolint package headscale import ( @@ -41,7 +40,11 @@ type IntegrationTestSuite struct { joinWaitGroup sync.WaitGroup } -func TestIntegrationTestSuite(t *testing.T) { +func TestIntegrationGeneralTestSuite(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration tests due to short flag") + } + saveLogs, err := GetEnvBool("HEADSCALE_INTEGRATION_SAVE_LOG") if err != nil { saveLogs = false @@ -504,7 +507,7 @@ func getIPsfromIPNstate(status ipnstate.Status) []netip.Addr { return ips } -// TODO: Adopt test for cross communication between namespaces +// TODO: Adopt test for cross communication between namespaces. func (s *IntegrationTestSuite) TestPingAllPeersByAddress() { for _, scales := range s.namespaces { ips, err := getIPs(scales.tailscales) diff --git a/integration_oidc_test.go b/integration_oidc_test.go index ba0b00f..8ca46db 100644 --- a/integration_oidc_test.go +++ b/integration_oidc_test.go @@ -1,5 +1,4 @@ -//go:build integration_oidc - +//nolint package headscale import ( @@ -45,7 +44,11 @@ type IntegrationOIDCTestSuite struct { joinWaitGroup sync.WaitGroup } -func TestOIDCIntegrationTestSuite(t *testing.T) { +func TestIntegrationOIDCTestSuite(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration tests due to short flag") + } + saveLogs, err := GetEnvBool("HEADSCALE_INTEGRATION_SAVE_LOG") if err != nil { saveLogs = false @@ -197,7 +200,7 @@ oidc: log.Println(config) configPath := path.Join(currentPath, "integration_test/etc_oidc/config.yaml") - err = os.WriteFile(configPath, []byte(config), 0644) + err = os.WriteFile(configPath, []byte(config), 0o644) if err != nil { s.FailNow(fmt.Sprintf("Could not write config: %s", err), "") }