Skip to content

Commit

Permalink
Merge pull request #1760 from dgageot/remove-duplication-integration-…
Browse files Browse the repository at this point in the history
…tests

Remove duplication integration tests
  • Loading branch information
nkubala authored Mar 11, 2019
2 parents 7212422 + ef51e17 commit fce6524
Show file tree
Hide file tree
Showing 27 changed files with 533 additions and 358 deletions.
11 changes: 2 additions & 9 deletions integration/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ limitations under the License.
package integration

import (
"os/exec"
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/GoogleContainerTools/skaffold/integration/skaffold"
)

func TestBuild(t *testing.T) {
Expand Down Expand Up @@ -57,13 +56,7 @@ func TestBuild(t *testing.T) {

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)
}
skaffold.Build(test.args...).InDir(test.dir).RunOrFail(t)
})
}
}
173 changes: 42 additions & 131 deletions integration/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,162 +17,73 @@ limitations under the License.
package integration

import (
"fmt"
"os/exec"
"strings"
"testing"

"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/GoogleContainerTools/skaffold/integration/skaffold"
"github.com/GoogleContainerTools/skaffold/testutil"
yaml "gopkg.in/yaml.v2"
)

func TestListConfig(t *testing.T) {
func TestConfigListForContext(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

baseConfig := &config.Config{
Global: &config.ContextConfig{
DefaultRepo: "global-repository",
},
ContextConfigs: []*config.ContextConfig{
{
Kubecontext: "test-context",
DefaultRepo: "context-local-repository",
},
},
}
out := skaffold.Config("list", "-c", "testdata/config/config.yaml", "-k", "test-context").RunOrFail(t)

c, _ := yaml.Marshal(*baseConfig)
cfg, teardown := testutil.TempFile(t, "config", c)
defer teardown()
testutil.CheckContains(t, "default-repo: context-local-repository", string(out))
}

type testListCase struct {
description string
kubectx string
expectedOutput []string
func TestConfigListForAll(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

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",
},
},
}
out := skaffold.Config("list", "-c", "testdata/config/config.yaml", "--all").RunOrFail(t)

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)
}
}
})
for _, output := range []string{
"global:",
"default-repo: global-repository",
"kube-context: test-context",
"default-repo: context-local-repository",
} {
testutil.CheckContains(t, output, string(out))
}
}

func TestSetConfig(t *testing.T) {
func TestFailToSetUnrecognizedValue(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

baseConfig := &config.Config{
Global: &config.ContextConfig{
DefaultRepo: "global-repository",
},
ContextConfigs: []*config.ContextConfig{
{
Kubecontext: "test-context",
DefaultRepo: "context-local-repository",
},
},
}
_, err := skaffold.Config("set", "doubt-this-will-ever-be-a-config-key", "VALUE", "-c", "testdata/config/config.yaml", "--global").Run(t)

c, _ := yaml.Marshal(*baseConfig)
cfg, teardown := testutil.TempFile(t, "config", c)
defer teardown()
testutil.CheckError(t, true, err)
}

type testSetCase struct {
description string
kubectx string
key string
shouldErr bool
func TestSetDefaultRepoForContext(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

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,
},
}
file, delete := testutil.TempFile(t, "config", nil)
defer delete()

skaffold.Config("set", "default-repo", "REPO1", "-c", file, "-k", "test-context").RunOrFail(t)
out := skaffold.Config("list", "-c", file, "-k", "test-context").RunOrFail(t)

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)
}
})
testutil.CheckContains(t, "default-repo: REPO1", string(out))
}

func TestSetGlobalDefaultRepo(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

file, delete := testutil.TempFile(t, "config", nil)
defer delete()

skaffold.Config("set", "default-repo", "REPO2", "-c", file, "--global").RunOrFail(t)
out := skaffold.Config("list", "-c", file, "--all").RunOrFail(t)

testutil.CheckContains(t, "default-repo: REPO2", string(out))
}
25 changes: 6 additions & 19 deletions integration/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ 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"
"github.com/GoogleContainerTools/skaffold/integration/skaffold"
"github.com/GoogleContainerTools/skaffold/testutil"
)

func TestDeploy(t *testing.T) {
Expand All @@ -33,21 +31,10 @@ func TestDeploy(t *testing.T) {
ns, client, deleteNs := SetupNamespace(t)
defer deleteNs()

RunSkaffold(t, "deploy", "examples/kustomize", ns.Name, "", nil, "--images", "index.docker.io/library/busybox:1")
skaffold.Deploy("--images", "index.docker.io/library/busybox:1").InDir("examples/kustomize").InNs(ns.Name).RunOrFail(t)

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)
}
dep := client.GetDeployment("kustomize-test")
testutil.CheckDeepEqual(t, "index.docker.io/library/busybox:1", dep.Spec.Template.Spec.Containers[0].Image)

RunSkaffold(t, "delete", "examples/kustomize", ns.Name, "", nil)
skaffold.Delete().InDir("examples/kustomize").InNs(ns.Name).RunOrFail(t)
}
34 changes: 9 additions & 25 deletions integration/dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ 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"
"github.com/GoogleContainerTools/skaffold/integration/skaffold"
"github.com/GoogleContainerTools/skaffold/testutil"
"k8s.io/apimachinery/pkg/util/wait"
)

Expand All @@ -35,38 +34,23 @@ func TestDev(t *testing.T) {
defer Run(t, "testdata/dev", "rm", "foo")

// Run skaffold build first to fail quickly on a build failure
RunSkaffold(t, "build", "testdata/dev", "", "", nil)
skaffold.Build().InDir("testdata/dev").RunOrFail(t)

ns, client, deleteNs := SetupNamespace(t)
defer deleteNs()

cancel := make(chan bool)
go RunSkaffoldNoFail(cancel, "dev", "testdata/dev", ns.Name, "", nil)
defer func() { cancel <- true }()
stop := skaffold.Dev().InDir("testdata/dev").InNs(ns.Name).RunBackground(t)
defer stop()

deployName := "test-dev"
if err := kubernetesutil.WaitForDeploymentToStabilize(context.Background(), client, ns.Name, deployName, 10*time.Minute); err != nil {
t.Fatalf("Timed out waiting for deployment to stabilize")
}

dep, err := client.AppsV1().Deployments(ns.Name).Get(deployName, meta_v1.GetOptions{})
if err != nil {
t.Fatalf("Could not find dep: %s %s", ns.Name, deployName)
}
dep := client.GetDeployment("test-dev")

// Make a change to foo so that dev is forced to delete the Deployment and redeploy
Run(t, "testdata/dev", "sh", "-c", "echo bar > foo")

// Make sure the old Deployment and the new Deployment are different
err = wait.PollImmediate(time.Millisecond*500, 10*time.Minute, func() (bool, error) {
newDep, err := client.AppsV1().Deployments(ns.Name).Get(deployName, meta_v1.GetOptions{})
if err != nil {
return false, nil
}

err := wait.PollImmediate(time.Millisecond*500, 10*time.Minute, func() (bool, error) {
newDep := client.GetDeployment("test-dev")
return dep.GetGeneration() != newDep.GetGeneration(), nil
})
if err != nil {
t.Fatalf("redeploy failed: %v", err)
}
testutil.CheckError(t, false, err)
}
19 changes: 3 additions & 16 deletions integration/fix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ limitations under the License.
package integration

import (
"bytes"
"os/exec"
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/GoogleContainerTools/skaffold/integration/skaffold"
)

func TestFix(t *testing.T) {
Expand All @@ -32,18 +30,7 @@ func TestFix(t *testing.T) {
ns, _, deleteNs := SetupNamespace(t)
defer deleteNs()

fixCmd := exec.Command("skaffold", "fix", "-f", "skaffold.yaml")
fixCmd.Dir = "testdata/fix"
out, err := util.RunCmdOut(fixCmd)
if err != nil {
t.Fatalf("skaffold fix: %v", err)
}

runCmd := exec.Command("skaffold", "run", "--namespace", ns.Name, "-f", "-")
runCmd.Dir = "testdata/fix"
runCmd.Stdin = bytes.NewReader(out)
out := skaffold.Fix().WithConfig("skaffold.yaml").InDir("testdata/fix").RunOrFail(t)

if out, err := util.RunCmdOut(runCmd); err != nil {
t.Fatalf("skaffold run: %v, %s", err, out)
}
skaffold.Run().WithConfig("-").InDir("testdata/fix").InNs(ns.Name).WithStdin(out).RunOrFail(t)
}
Loading

0 comments on commit fce6524

Please sign in to comment.