-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1678 from nkubala/integration
Restructure integration tests
- Loading branch information
Showing
10 changed files
with
734 additions
and
486 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// +build integration | ||
|
||
/* | ||
Copyright 2019 The Skaffold Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package integration | ||
|
||
import ( | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" | ||
) | ||
|
||
func TestBuild(t *testing.T) { | ||
tests := []struct { | ||
description string | ||
dir string | ||
args []string | ||
}{ | ||
{ | ||
description: "docker build", | ||
dir: "testdata/build", | ||
}, { | ||
description: "git tagger", | ||
dir: "testdata/tagPolicy", | ||
args: []string{"-p", "gitCommit"}, | ||
}, { | ||
description: "sha256 tagger", | ||
dir: "testdata/tagPolicy", | ||
args: []string{"-p", "sha256"}, | ||
}, { | ||
description: "dateTime tagger", | ||
dir: "testdata/tagPolicy", | ||
args: []string{"-p", "dateTime"}, | ||
}, { | ||
description: "envTemplate tagger", | ||
dir: "testdata/tagPolicy", | ||
args: []string{"-p", "envTemplate"}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.description, func(t *testing.T) { | ||
buildCmd := exec.Command("skaffold", append([]string{"build"}, test.args...)...) | ||
buildCmd.Dir = test.dir | ||
|
||
out, err := util.RunCmdOut(buildCmd) | ||
if err != nil { | ||
t.Fatalf("testing error: %v, %s", err, out) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
// +build integration | ||
|
||
/* | ||
Copyright 2019 The Skaffold Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package integration | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
|
||
yaml "gopkg.in/yaml.v2" | ||
|
||
"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/config" | ||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" | ||
"github.com/GoogleContainerTools/skaffold/testutil" | ||
) | ||
|
||
func TestListConfig(t *testing.T) { | ||
baseConfig := &config.Config{ | ||
Global: &config.ContextConfig{ | ||
DefaultRepo: "global-repository", | ||
}, | ||
ContextConfigs: []*config.ContextConfig{ | ||
{ | ||
Kubecontext: "test-context", | ||
DefaultRepo: "context-local-repository", | ||
}, | ||
}, | ||
} | ||
|
||
c, _ := yaml.Marshal(*baseConfig) | ||
cfg, teardown := testutil.TempFile(t, "config", c) | ||
defer teardown() | ||
|
||
type testListCase struct { | ||
description string | ||
kubectx string | ||
expectedOutput []string | ||
} | ||
|
||
var tests = []testListCase{ | ||
{ | ||
description: "list for test-context", | ||
kubectx: "test-context", | ||
expectedOutput: []string{"default-repo: context-local-repository"}, | ||
}, | ||
{ | ||
description: "list all", | ||
expectedOutput: []string{ | ||
"global:", | ||
"default-repo: global-repository", | ||
"kube-context: test-context", | ||
"default-repo: context-local-repository", | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.description, func(t *testing.T) { | ||
args := []string{"config", "list", "-c", cfg} | ||
if test.kubectx != "" { | ||
args = append(args, "-k", test.kubectx) | ||
} else { | ||
args = append(args, "--all") | ||
} | ||
cmd := exec.Command("skaffold", args...) | ||
rawOut, err := util.RunCmdOut(cmd) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
out := string(rawOut) | ||
for _, output := range test.expectedOutput { | ||
if !strings.Contains(out, output) { | ||
t.Errorf("expected output %s not found in output: %s", output, out) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestSetConfig(t *testing.T) { | ||
baseConfig := &config.Config{ | ||
Global: &config.ContextConfig{ | ||
DefaultRepo: "global-repository", | ||
}, | ||
ContextConfigs: []*config.ContextConfig{ | ||
{ | ||
Kubecontext: "test-context", | ||
DefaultRepo: "context-local-repository", | ||
}, | ||
}, | ||
} | ||
|
||
c, _ := yaml.Marshal(*baseConfig) | ||
cfg, teardown := testutil.TempFile(t, "config", c) | ||
defer teardown() | ||
|
||
type testSetCase struct { | ||
description string | ||
kubectx string | ||
key string | ||
shouldErr bool | ||
} | ||
|
||
var tests = []testSetCase{ | ||
{ | ||
description: "set default-repo for context", | ||
kubectx: "test-context", | ||
key: "default-repo", | ||
}, | ||
{ | ||
description: "set global default-repo", | ||
key: "default-repo", | ||
}, | ||
{ | ||
description: "fail to set unrecognized value", | ||
key: "doubt-this-will-ever-be-a-config-value", | ||
shouldErr: true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.description, func(t *testing.T) { | ||
value := util.RandomID() | ||
args := []string{"config", "set", test.key, value} | ||
args = append(args, "-c", cfg) | ||
if test.kubectx != "" { | ||
args = append(args, "-k", test.kubectx) | ||
} else { | ||
args = append(args, "--global") | ||
} | ||
cmd := exec.Command("skaffold", args...) | ||
if err := util.RunCmd(cmd); err != nil { | ||
if test.shouldErr { | ||
return | ||
} | ||
t.Error(err) | ||
} | ||
|
||
listArgs := []string{"config", "list", "-c", cfg} | ||
if test.kubectx != "" { | ||
listArgs = append(listArgs, "-k", test.kubectx) | ||
} else { | ||
listArgs = append(listArgs, "--all") | ||
} | ||
listCmd := exec.Command("skaffold", listArgs...) | ||
out, err := util.RunCmdOut(listCmd) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
t.Log(string(out)) | ||
if !strings.Contains(string(out), fmt.Sprintf("%s: %s", test.key, value)) { | ||
t.Errorf("value %s not set correctly", test.key) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// +build integration | ||
|
||
/* | ||
Copyright 2019 The Skaffold Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package integration | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"testing" | ||
|
||
kubernetesutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" | ||
) | ||
|
||
func TestDeploy(t *testing.T) { | ||
ns, deleteNs := SetupNamespace(t) | ||
defer deleteNs() | ||
|
||
RunSkaffold(t, "deploy", "examples/kustomize", ns.Name, "", nil, "--images", "index.docker.io/library/busybox:1") | ||
|
||
depName := "kustomize-test" | ||
if err := kubernetesutil.WaitForDeploymentToStabilize(context.Background(), Client, ns.Name, depName, 10*time.Minute); err != nil { | ||
t.Fatalf("Timed out waiting for deployment to stabilize") | ||
} | ||
|
||
dep, err := Client.AppsV1().Deployments(ns.Name).Get(depName, meta_v1.GetOptions{}) | ||
if err != nil { | ||
t.Fatalf("Could not find deployment: %s %s", ns.Name, depName) | ||
} | ||
|
||
if dep.Spec.Template.Spec.Containers[0].Image != "index.docker.io/library/busybox:1" { | ||
t.Fatalf("Wrong image name in kustomized deployment: %s", dep.Spec.Template.Spec.Containers[0].Image) | ||
} | ||
|
||
RunSkaffold(t, "delete", "examples/kustomize", ns.Name, "", nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// +build integration | ||
|
||
/* | ||
Copyright 2019 The Skaffold Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package integration | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
kubernetesutil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" | ||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
) | ||
|
||
func TestDev(t *testing.T) { | ||
ns, deleteNs := SetupNamespace(t) | ||
defer deleteNs() | ||
|
||
Run(t, "examples/test-dev-job", "touch", "foo") | ||
defer Run(t, "examples/test-dev-job", "rm", "foo") | ||
|
||
cancel := make(chan bool) | ||
go RunSkaffoldNoFail(cancel, "dev", "examples/test-dev-job", ns.Name, "", nil) | ||
defer func() { cancel <- true }() | ||
|
||
jobName := "test-dev-job" | ||
if err := kubernetesutil.WaitForJobToStabilize(context.Background(), Client, ns.Name, jobName, 10*time.Minute); err != nil { | ||
t.Fatalf("Timed out waiting for job to stabilize") | ||
} | ||
|
||
job, err := Client.BatchV1().Jobs(ns.Name).Get(jobName, meta_v1.GetOptions{}) | ||
if err != nil { | ||
t.Fatalf("Could not find job: %s %s", ns.Name, jobName) | ||
} | ||
|
||
time.Sleep(5 * time.Second) | ||
|
||
// Make a change to foo so that dev is forced to delete the job and redeploy | ||
Run(t, "examples/test-dev-job", "sh", "-c", "echo bar > foo") | ||
|
||
// Make sure the UID of the old Job and the UID of the new Job is different | ||
err = wait.PollImmediate(time.Millisecond*500, 10*time.Minute, func() (bool, error) { | ||
newJob, err := Client.BatchV1().Jobs(ns.Name).Get(job.Name, meta_v1.GetOptions{}) | ||
if err != nil { | ||
return false, nil | ||
} | ||
return job.GetUID() != newJob.GetUID(), nil | ||
}) | ||
if err != nil { | ||
t.Fatalf("redeploy failed: %v", err) | ||
} | ||
} |
Oops, something went wrong.