From eda432148687f467c4d425235aa8f75c5d8c83c8 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Fri, 14 Oct 2022 10:37:13 +0200 Subject: [PATCH] Skip integration tests on short or lack of docker Signed-off-by: Kristoffer Dalby --- integration/dockertestutil/config.go | 14 +++++++++++++- integration/scenario_test.go | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/integration/dockertestutil/config.go b/integration/dockertestutil/config.go index 2a5ac144..4dc3ee33 100644 --- a/integration/dockertestutil/config.go +++ b/integration/dockertestutil/config.go @@ -1,6 +1,18 @@ package dockertestutil -import "github.com/ory/dockertest/v3/docker" +import ( + "os" + + "github.com/ory/dockertest/v3/docker" +) + +func IsRunningInContainer() bool { + if _, err := os.Stat("/.dockerenv"); err != nil { + return false + } + + return true +} func DockerRestartPolicy(config *docker.HostConfig) { // set AutoRemove to true so that stopped container goes away by itself on error *immediately*. diff --git a/integration/scenario_test.go b/integration/scenario_test.go index cb4aa859..8811b2f8 100644 --- a/integration/scenario_test.go +++ b/integration/scenario_test.go @@ -3,10 +3,24 @@ package integration import ( "testing" + "github.com/juanfont/headscale/integration/dockertestutil" "github.com/juanfont/headscale/integration/tsic" ) +func IntegrationSkip(t *testing.T) { + t.Helper() + + if !dockertestutil.IsRunningInContainer() { + t.Skip("not running in docker, skipping") + } + + if testing.Short() { + t.Skip("skipping integration tests due to short flag") + } +} + func TestHeadscale(t *testing.T) { + IntegrationSkip(t) var err error scenario, err := NewScenario() @@ -52,6 +66,8 @@ func TestHeadscale(t *testing.T) { } func TestCreateTailscale(t *testing.T) { + IntegrationSkip(t) + var scenario *Scenario var err error @@ -84,6 +100,8 @@ func TestCreateTailscale(t *testing.T) { } func TestTailscaleNodesJoiningHeadcale(t *testing.T) { + IntegrationSkip(t) + var err error namespace := "join-node-test"