Skip to content

Commit

Permalink
Merge pull request #865 from kradalby/integration-no-build-tags
Browse files Browse the repository at this point in the history
Do not use build tags for running integration tests
  • Loading branch information
juanfont authored Oct 18, 2022
2 parents e96bcee + 2f36a11 commit a395045
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 25 deletions.
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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=";
Expand Down
9 changes: 6 additions & 3 deletions integration_cli_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration_cli

//nolint
package headscale

import (
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions integration_common_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration

//nolint
package headscale

import (
Expand Down Expand Up @@ -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.
Expand Down
13 changes: 7 additions & 6 deletions integration_embedded_derp_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration_derp

//nolint
package headscale

import (
Expand All @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -120,7 +122,6 @@ func (s *IntegrationDERPTestSuite) SetupSuite() {
}

headscaleOptions := &dockertest.RunOptions{

Name: headscaleDerpHostname,
Mounts: []string{
fmt.Sprintf(
Expand Down
11 changes: 7 additions & 4 deletions integration_general_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration_general

//nolint
package headscale

import (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions integration_oidc_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration_oidc

//nolint
package headscale

import (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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), "")
}
Expand Down

0 comments on commit a395045

Please sign in to comment.