Skip to content

Commit

Permalink
Merge pull request GoogleContainerTools#3358 from dgageot/simplify-in…
Browse files Browse the repository at this point in the history
…t-tests

Simplify handling of GCP only tests
  • Loading branch information
nkubala authored Dec 11, 2019
2 parents f454cb5 + 0e24424 commit a995415
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 247 deletions.
45 changes: 13 additions & 32 deletions integration/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ import (
const imageName = "simple-build:"

func TestBuild(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

tests := []struct {
Expand Down Expand Up @@ -136,11 +133,8 @@ func TestBuild(t *testing.T) {

//see integration/testdata/README.md for details
func TestBuildInCluster(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if !ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is gcp only")
if testing.Short() || !RunOnGCP() {
t.Skip("skipping GCP integration test")
}

testutil.Run(t, "", func(t *testutil.T) {
Expand Down Expand Up @@ -317,11 +311,8 @@ func failNowIfError(t *testing.T, err error) {

// TestExpectedBuildFailures verifies that `skaffold build` fails in expected ways
func TestExpectedBuildFailures(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

tests := []struct {
Expand Down Expand Up @@ -350,14 +341,10 @@ func TestExpectedBuildFailures(t *testing.T) {
}
}

// run on GCP as this test requires a load balancer
func TestBuildKanikoInsecureRegistry(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

// run on GCP as this test requires a load balancer
if !ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is gcp only")
if testing.Short() || !RunOnGCP() {
t.Skip("skipping GCP integration test")
}

ns, k8sClient, cleanupNs := SetupNamespace(t)
Expand Down Expand Up @@ -397,11 +384,8 @@ func getExternalIP(t *testing.T, c *NSKubernetesClient, ns string) string {
}

func TestBuildGCBWithDefaultRepo(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if !ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is gcp only")
if testing.Short() || !RunOnGCP() {
t.Skip("skipping GCP integration test")
}

// The GCB project (k8s-skaffold) has to be deduced from artifact's image name
Expand All @@ -411,11 +395,8 @@ func TestBuildGCBWithDefaultRepo(t *testing.T) {
}

func TestBuildKanikoWithDefaultRepo(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if !ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is gcp only")
if testing.Short() || !RunOnGCP() {
t.Skip("skipping GCP integration test")
}

// The GCS project (k8s-skaffold) has to be deduced from artifact's image name
Expand Down
7 changes: 2 additions & 5 deletions integration/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ import (
)

func TestCacheAPITriggers(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

// Run skaffold build first to cache artifacts.
Expand Down
35 changes: 10 additions & 25 deletions integration/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ import (
)

func TestConfigListForContext(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

out := skaffold.Config("list", "-c", "testdata/config/config.yaml", "-k", "test-context").RunOrFailOutput(t)
Expand All @@ -37,11 +34,8 @@ func TestConfigListForContext(t *testing.T) {
}

func TestConfigListForAll(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

out := skaffold.Config("list", "-c", "testdata/config/config.yaml", "--all").RunOrFailOutput(t)
Expand All @@ -57,11 +51,8 @@ func TestConfigListForAll(t *testing.T) {
}

func TestFailToSetUnrecognizedValue(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

err := skaffold.Config("set", "doubt-this-will-ever-be-a-config-key", "VALUE", "-c", "testdata/config/config.yaml", "--global").Run(t)
Expand All @@ -70,11 +61,8 @@ func TestFailToSetUnrecognizedValue(t *testing.T) {
}

func TestSetDefaultRepoForContext(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

file, delete := testutil.TempFile(t, "config", nil)
Expand All @@ -87,11 +75,8 @@ func TestSetDefaultRepoForContext(t *testing.T) {
}

func TestSetGlobalDefaultRepo(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

file, delete := testutil.TempFile(t, "config", nil)
Expand Down
7 changes: 2 additions & 5 deletions integration/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ import (
)

func TestDebug(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

tests := []struct {
Expand Down
28 changes: 8 additions & 20 deletions integration/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ import (
)

func TestBuildDeploy(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

ns, client, deleteNs := SetupNamespace(t)
Expand Down Expand Up @@ -83,11 +80,8 @@ func TestBuildDeploy(t *testing.T) {
}

func TestDeploy(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

ns, client, deleteNs := SetupNamespace(t)
Expand All @@ -102,11 +96,8 @@ func TestDeploy(t *testing.T) {
}

func TestDeployTail(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

ns, _, deleteNs := SetupNamespace(t)
Expand Down Expand Up @@ -139,11 +130,8 @@ func TestDeployTail(t *testing.T) {
}

func TestDeployWithInCorrectConfig(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

ns, _, deleteNs := SetupNamespace(t)
Expand Down
40 changes: 14 additions & 26 deletions integration/dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ import (
)

func TestDev(t *testing.T) {
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

tests := []struct {
description string
trigger string
Expand All @@ -51,13 +55,6 @@ func TestDev(t *testing.T) {
}
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
}

Run(t, "testdata/dev", "sh", "-c", "echo foo > foo")
defer Run(t, "testdata/dev", "rm", "foo")

Expand Down Expand Up @@ -86,11 +83,8 @@ func TestDev(t *testing.T) {
}

func TestDevAPITriggers(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

Run(t, "testdata/dev", "sh", "-c", "echo foo > foo")
Expand Down Expand Up @@ -173,11 +167,8 @@ func TestDevAPITriggers(t *testing.T) {
}

func TestDevPortForward(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

// Run skaffold build first to fail quickly on a build failure
Expand Down Expand Up @@ -231,11 +222,8 @@ func TestDevPortForward(t *testing.T) {
}

func TestDevPortForwardGKELoadBalancer(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if !ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is gcp only")
if testing.Short() || !RunOnGCP() {
t.Skip("skipping GCP integration test")
}

// Run skaffold build first to fail quickly on a build failure
Expand Down Expand Up @@ -369,11 +357,11 @@ func readEventAPIStream(client proto.SkaffoldServiceClient, t *testing.T, retrie
}

func TestDev_WithKubecontextOverride(t *testing.T) {
testutil.Run(t, "skaffold run with kubecontext override", func(t *testutil.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

testutil.Run(t, "skaffold run with kubecontext override", func(t *testutil.T) {
dir := "examples/getting-started"
pods := []string{"getting-started"}

Expand Down
7 changes: 2 additions & 5 deletions integration/diagnose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ import (
)

func TestDiagnose(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

examples, err := folders("examples")
Expand Down
7 changes: 2 additions & 5 deletions integration/fix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ import (
)

func TestFix(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

ns, _, deleteNs := SetupNamespace(t)
Expand Down
8 changes: 2 additions & 6 deletions integration/generate_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ type configContents struct {
}

func TestGeneratePipeline(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if ShouldRunGCPOnlyTests() {
t.Skip("skipping test that is not gcp only")
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

tests := []struct {
Expand Down Expand Up @@ -74,7 +71,6 @@ func TestGeneratePipeline(t *testing.T) {
skipCheck: true,
},
}

for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
args, contents, err := getOriginalContents(test.args, test.dir, test.configFiles)
Expand Down
7 changes: 2 additions & 5 deletions integration/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ const (
)

func TestHelmDeploy(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if !ShouldRunGCPOnlyTests() {
t.Skip("skipping gcp only test")
if testing.Short() || !RunOnGCP() {
t.Skip("skipping GCP integration test")
}

helmDir := "testdata/helm"
Expand Down
Loading

0 comments on commit a995415

Please sign in to comment.