-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daisy Guo
committed
Nov 17, 2020
1 parent
fad39a4
commit 0c910c6
Showing
1 changed file
with
97 additions
and
0 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,97 @@ | ||
// 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 ( | ||
"testing" | ||
|
||
"gotest.tools/assert" | ||
|
||
"knative.dev/client/lib/test" | ||
"knative.dev/client/pkg/util" | ||
pkgtest "knative.dev/pkg/test" | ||
) | ||
|
||
func TestSourceContainer(t *testing.T) { | ||
t.Parallel() | ||
it, err := test.NewKnTest() | ||
assert.NilError(t, err) | ||
defer func() { | ||
err := it.Teardown() | ||
assert.NilError(t, err) | ||
}() | ||
|
||
r := test.NewKnRunResultCollector(t, it) | ||
defer r.DumpIfFailed() | ||
|
||
test.ServiceCreate(r, "testsvc0") | ||
|
||
t.Log("create container source with a sink to a service") | ||
containerSourceCreate(r, "testsource0", "ksvc:testsvc0") | ||
containerSourceListOutputName(r, "testsource0") | ||
|
||
t.Log("list sources") | ||
output := sourceList(r) | ||
assert.Check(t, util.ContainsAll(output, "NAME", "IMAGE", "SINK", "READY")) | ||
assert.Check(t, util.ContainsAll(output, "testsource0", "grpc-ping", "ksvc:testsvc0")) | ||
|
||
t.Log("delete container sources") | ||
containerSourceDelete(r, "testsource0") | ||
|
||
t.Log("create container source with a missing sink service") | ||
containerSourceCreateMissingSink(r, "testsource2", "ksvc:unknown") | ||
|
||
t.Log("update container source sink service") | ||
containerSourceCreate(r, "testsource3", "ksvc:testsvc0") | ||
test.ServiceCreate(r, "testsvc1") | ||
containerSourceUpdateSink(r, "testsource3", "ksvc:testsvc1") | ||
jpSinkRefNameInSpec := "jsonpath={.spec.sink.ref.name}" | ||
out, err := test.GetResourceFieldsWithJSONPath(t, it, "containersource.sources.knative.dev", "testsource3", jpSinkRefNameInSpec) | ||
assert.NilError(t, err) | ||
assert.Equal(t, out, "testsvc1") | ||
} | ||
|
||
func containerSourceCreate(r *test.KnRunResultCollector, sourceName string, sink string) { | ||
out := r.KnTest().Kn().Run("source", "container", "create", sourceName, "--image", pkgtest.ImagePath("grpc-ping"), "--port", "h2c:8080", "--sink", sink) | ||
r.AssertNoError(out) | ||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "container", "source", sourceName, "created", "namespace", r.KnTest().Kn().Namespace())) | ||
} | ||
|
||
func containerSourceListOutputName(r *test.KnRunResultCollector, containerSources ...string) { | ||
out := r.KnTest().Kn().Run("source", "container", "list", "--output", "name") | ||
r.AssertNoError(out) | ||
assert.Check(r.T(), util.ContainsAll(out.Stdout, containerSources...)) | ||
} | ||
|
||
func containerSourceCreateMissingSink(r *test.KnRunResultCollector, sourceName string, sink string) { | ||
out := r.KnTest().Kn().Run("source", "container", "create", sourceName, "--image", pkgtest.ImagePath("grpc-ping"), "--port", "h2c:8080", "--sink", sink) | ||
r.AssertError(out) | ||
assert.Check(r.T(), util.ContainsAll(out.Stderr, "services.serving.knative.dev", "not found")) | ||
} | ||
|
||
func containerSourceDelete(r *test.KnRunResultCollector, sourceName string) { | ||
out := r.KnTest().Kn().Run("source", "container", "delete", sourceName) | ||
r.AssertNoError(out) | ||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "container", "source", sourceName, "deleted", "namespace", r.KnTest().Kn().Namespace())) | ||
} | ||
|
||
func containerSourceUpdateSink(r *test.KnRunResultCollector, sourceName string, sink string) { | ||
out := r.KnTest().Kn().Run("source", "container", "update", sourceName, "--sink", sink) | ||
r.AssertNoError(out) | ||
assert.Check(r.T(), util.ContainsAll(out.Stdout, sourceName, "updated", "namespace", r.KnTest().Kn().Namespace())) | ||
} |