Skip to content

Commit

Permalink
Add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dsimansk committed Aug 3, 2021
1 parent ad4e8da commit cd15149
Show file tree
Hide file tree
Showing 58 changed files with 5,892 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hack/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ import (
_ "k8s.io/code-generator"
_ "k8s.io/code-generator/cmd/deepcopy-gen"
_ "knative.dev/serving/test/test_images/grpc-ping"
_ "knative.dev/serving/test/test_images/multicontainer/servingcontainer"
_ "knative.dev/serving/test/test_images/multicontainer/sidecarcontainer"
)
92 changes: 92 additions & 0 deletions test/e2e/container_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright 2019 The Knative 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 im
// See the License for the specific language governing permissions and
// limitations under the License.

// +build e2e
// +build !serving

package e2e

import (
"io/ioutil"
"knative.dev/client/pkg/util"
pkgtest "knative.dev/pkg/test"
"os"
"path/filepath"
"testing"

"gotest.tools/v3/assert"

"knative.dev/client/lib/test"
)

func TestMultiContainers(t *testing.T) {
t.Parallel()
it, err := test.NewKnTest()
assert.NilError(t, err)
defer func() {
assert.NilError(t, it.Teardown())
}()

r := test.NewKnRunResultCollector(t, it)
defer r.DumpIfFailed()

tempDir, err := ioutil.TempDir("", "kn-file")
defer os.RemoveAll(tempDir)
assert.NilError(t, err)

t.Log("Creating a multicontainer service")
out := addContainer(r, "sidecar", pkgtest.ImagePath("sidecarcontainer"))
test.CreateFile("sidecar.yaml", out.Stdout, tempDir, test.FileModeReadWrite)
createServiceWithSidecar(r, "testsvc0", filepath.Join(tempDir, "sidecar.yaml"))

t.Log("Adding container no error")
out = addContainer(r, "foo", pkgtest.ImagePath("sidecarcontainer"))
r.AssertNoError(out)
assert.Assert(t, util.ContainsAllIgnoreCase(out.Stdout,"containers", "foo", pkgtest.ImagePath("sidecarcontainer")))

t.Log("Adding container without name error")
out = addContainer(r, "", pkgtest.ImagePath("sidecarcontainer"))
r.AssertError(out)
assert.Assert(t, util.ContainsAllIgnoreCase(out.Stderr, "requires", "container", "name"))

t.Log("Adding container without image error")
out = addContainer(r, "foo", "")
r.AssertError(out)
assert.Assert(t, util.ContainsAllIgnoreCase(out.Stderr,"requires", "image", "name"))
}

func addContainer(r *test.KnRunResultCollector, containerName, image string) test.KnRunResult {
args := []string{"container", "add"}
if containerName != "" {
args = append(args, containerName)
}
if image != "" {
args = append(args, "--image", image)
}

out := r.KnTest().Kn().RunNoNamespace(args...)
return out
}

func createServiceWithSidecar(r *test.KnRunResultCollector, serviceName, file string) {
args := []string{"service", "create", serviceName,
"--image", pkgtest.ImagePath("servingcontainer"),
"--port", "8881",
"--containers", file,
}

out := r.KnTest().Kn().Run(args...)
r.AssertNoError(out)
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "service", serviceName, "creating", "namespace", r.KnTest().Kn().Namespace(), "ready"))
}
16 changes: 16 additions & 0 deletions test/test_images/multicontainer/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2021 The Knative 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
#
# https://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.

- image: ko://knative.dev/serving/test/test_images/multicontainer/servingcontainer
- image: ko://knative.dev/serving/test/test_images/multicontainer/sidecarcontainer
66 changes: 66 additions & 0 deletions vendor/golang.org/x/sync/errgroup/errgroup.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cd15149

Please sign in to comment.