mirror of
https://github.com/juanfont/headscale.git
synced 2025-01-19 10:20:05 +09:00
Merge pull request #865 from kradalby/integration-no-build-tags
Do not use build tags for running integration tests
This commit is contained in:
commit
a39504510a
7 changed files with 40 additions and 25 deletions
14
Makefile
14
Makefile
|
@ -22,7 +22,7 @@ build:
|
||||||
dev: lint test build
|
dev: lint test build
|
||||||
|
|
||||||
test:
|
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
|
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 network create headscale-test || true
|
||||||
docker run -t --rm \
|
docker run -t --rm \
|
||||||
--network headscale-test \
|
--network headscale-test \
|
||||||
|
-v ~/.cache/hs-integration-go:/go \
|
||||||
-v $$PWD:$$PWD -w $$PWD \
|
-v $$PWD:$$PWD -w $$PWD \
|
||||||
-v /var/run/docker.sock:/var/run/docker.sock golang:1 \
|
-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:
|
test_integration_derp:
|
||||||
docker network rm $$(docker network ls --filter name=headscale --quiet) || true
|
docker network rm $$(docker network ls --filter name=headscale --quiet) || true
|
||||||
docker network create headscale-test || true
|
docker network create headscale-test || true
|
||||||
docker run -t --rm \
|
docker run -t --rm \
|
||||||
--network headscale-test \
|
--network headscale-test \
|
||||||
|
-v ~/.cache/hs-integration-go:/go \
|
||||||
-v $$PWD:$$PWD -w $$PWD \
|
-v $$PWD:$$PWD -w $$PWD \
|
||||||
-v /var/run/docker.sock:/var/run/docker.sock golang:1 \
|
-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:
|
test_integration_general:
|
||||||
docker network rm $$(docker network ls --filter name=headscale --quiet) || true
|
docker network rm $$(docker network ls --filter name=headscale --quiet) || true
|
||||||
docker network create headscale-test || true
|
docker network create headscale-test || true
|
||||||
docker run -t --rm \
|
docker run -t --rm \
|
||||||
--network headscale-test \
|
--network headscale-test \
|
||||||
|
-v ~/.cache/hs-integration-go:/go \
|
||||||
-v $$PWD:$$PWD -w $$PWD \
|
-v $$PWD:$$PWD -w $$PWD \
|
||||||
-v /var/run/docker.sock:/var/run/docker.sock golang:1 \
|
-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:
|
test_integration_oidc:
|
||||||
docker network rm $$(docker network ls --filter name=headscale --quiet) || true
|
docker network rm $$(docker network ls --filter name=headscale --quiet) || true
|
||||||
docker network create headscale-test || true
|
docker network create headscale-test || true
|
||||||
docker run -t --rm \
|
docker run -t --rm \
|
||||||
--network headscale-test \
|
--network headscale-test \
|
||||||
|
-v ~/.cache/hs-integration-go:/go \
|
||||||
-v $$PWD:$$PWD -w $$PWD \
|
-v $$PWD:$$PWD -w $$PWD \
|
||||||
-v /var/run/docker.sock:/var/run/docker.sock golang:1 \
|
-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:
|
coverprofile_func:
|
||||||
go tool cover -func=coverage.out
|
go tool cover -func=coverage.out
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
version = headscaleVersion;
|
version = headscaleVersion;
|
||||||
src = pkgs.lib.cleanSource self;
|
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,
|
# 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.
|
# update this if you have a mismatch after doing a change to thos files.
|
||||||
vendorSha256 = "sha256-DosFCSiQ5FURbIrt4NcPGkExc84t2MGMqe9XLxNHdIM=";
|
vendorSha256 = "sha256-DosFCSiQ5FURbIrt4NcPGkExc84t2MGMqe9XLxNHdIM=";
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
//go:build integration_cli
|
//nolint
|
||||||
|
|
||||||
package headscale
|
package headscale
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -28,7 +27,11 @@ type IntegrationCLITestSuite struct {
|
||||||
env []string
|
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)
|
s := new(IntegrationCLITestSuite)
|
||||||
|
|
||||||
suite.Run(t, s)
|
suite.Run(t, s)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
//go:build integration
|
//nolint
|
||||||
|
|
||||||
package headscale
|
package headscale
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -328,7 +327,6 @@ func GetEnvBool(key string) (bool, error) {
|
||||||
func GetFirstOrCreateNetwork(pool *dockertest.Pool, name string) (dockertest.Network, error) {
|
func GetFirstOrCreateNetwork(pool *dockertest.Pool, name string) (dockertest.Network, error) {
|
||||||
networks, err := pool.NetworksByName(name)
|
networks, err := pool.NetworksByName(name)
|
||||||
if err != nil || len(networks) == 0 {
|
if err != nil || len(networks) == 0 {
|
||||||
|
|
||||||
if _, err := pool.CreateNetwork(name); err == nil {
|
if _, err := pool.CreateNetwork(name); err == nil {
|
||||||
// Create does not give us an updated version of the resource, so we need to
|
// Create does not give us an updated version of the resource, so we need to
|
||||||
// get it again.
|
// get it again.
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
//go:build integration_derp
|
//nolint
|
||||||
|
|
||||||
package headscale
|
package headscale
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -17,13 +16,12 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ccding/go-stun/stun"
|
||||||
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||||
"github.com/ory/dockertest/v3"
|
"github.com/ory/dockertest/v3"
|
||||||
"github.com/ory/dockertest/v3/docker"
|
"github.com/ory/dockertest/v3/docker"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/ccding/go-stun/stun"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -46,7 +44,11 @@ type IntegrationDERPTestSuite struct {
|
||||||
joinWaitGroup sync.WaitGroup
|
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")
|
saveLogs, err := GetEnvBool("HEADSCALE_INTEGRATION_SAVE_LOG")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
saveLogs = false
|
saveLogs = false
|
||||||
|
@ -120,7 +122,6 @@ func (s *IntegrationDERPTestSuite) SetupSuite() {
|
||||||
}
|
}
|
||||||
|
|
||||||
headscaleOptions := &dockertest.RunOptions{
|
headscaleOptions := &dockertest.RunOptions{
|
||||||
|
|
||||||
Name: headscaleDerpHostname,
|
Name: headscaleDerpHostname,
|
||||||
Mounts: []string{
|
Mounts: []string{
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
//go:build integration_general
|
//nolint
|
||||||
|
|
||||||
package headscale
|
package headscale
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -41,7 +40,11 @@ type IntegrationTestSuite struct {
|
||||||
joinWaitGroup sync.WaitGroup
|
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")
|
saveLogs, err := GetEnvBool("HEADSCALE_INTEGRATION_SAVE_LOG")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
saveLogs = false
|
saveLogs = false
|
||||||
|
@ -504,7 +507,7 @@ func getIPsfromIPNstate(status ipnstate.Status) []netip.Addr {
|
||||||
return ips
|
return ips
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Adopt test for cross communication between namespaces
|
// TODO: Adopt test for cross communication between namespaces.
|
||||||
func (s *IntegrationTestSuite) TestPingAllPeersByAddress() {
|
func (s *IntegrationTestSuite) TestPingAllPeersByAddress() {
|
||||||
for _, scales := range s.namespaces {
|
for _, scales := range s.namespaces {
|
||||||
ips, err := getIPs(scales.tailscales)
|
ips, err := getIPs(scales.tailscales)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
//go:build integration_oidc
|
//nolint
|
||||||
|
|
||||||
package headscale
|
package headscale
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -45,7 +44,11 @@ type IntegrationOIDCTestSuite struct {
|
||||||
joinWaitGroup sync.WaitGroup
|
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")
|
saveLogs, err := GetEnvBool("HEADSCALE_INTEGRATION_SAVE_LOG")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
saveLogs = false
|
saveLogs = false
|
||||||
|
@ -197,7 +200,7 @@ oidc:
|
||||||
log.Println(config)
|
log.Println(config)
|
||||||
|
|
||||||
configPath := path.Join(currentPath, "integration_test/etc_oidc/config.yaml")
|
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 {
|
if err != nil {
|
||||||
s.FailNow(fmt.Sprintf("Could not write config: %s", err), "")
|
s.FailNow(fmt.Sprintf("Could not write config: %s", err), "")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue