mirror of https://github.com/knative/client.git
* fix(#772) refactored / simplified parameters to KnResultCollector * added Teardown() call in VersionTest
This commit is contained in:
parent
e88ee59d45
commit
395fc6c3b2
|
|
@ -38,6 +38,11 @@ func NewKn() Kn {
|
|||
return Kn{}
|
||||
}
|
||||
|
||||
// RunNoNamespace the 'kn' CLI with args but no namespace
|
||||
func (k Kn) RunNoNamespace(args ...string) KnRunResult {
|
||||
return RunKn("", args)
|
||||
}
|
||||
|
||||
// Run the 'kn' CLI with args
|
||||
func (k Kn) Run(args ...string) KnRunResult {
|
||||
return RunKn(k.namespace, args)
|
||||
|
|
|
|||
|
|
@ -42,18 +42,32 @@ type KnRunResult struct {
|
|||
type KnRunResultCollector struct {
|
||||
results []KnRunResult
|
||||
extraDumps []string
|
||||
|
||||
t *testing.T
|
||||
knTest *KnTest
|
||||
}
|
||||
|
||||
// NewKnRunResultCollector returns a new KnRunResultCollector
|
||||
func NewKnRunResultCollector(t *testing.T) *KnRunResultCollector {
|
||||
func NewKnRunResultCollector(t *testing.T, knTest *KnTest) *KnRunResultCollector {
|
||||
return &KnRunResultCollector{
|
||||
results: []KnRunResult{},
|
||||
extraDumps: []string{},
|
||||
|
||||
t: t,
|
||||
knTest: knTest,
|
||||
}
|
||||
}
|
||||
|
||||
// T returns the *testing.T object
|
||||
func (c *KnRunResultCollector) T() *testing.T {
|
||||
return c.t
|
||||
}
|
||||
|
||||
// KnTest returns the KnTest object
|
||||
func (c *KnRunResultCollector) KnTest() *KnTest {
|
||||
return c.knTest
|
||||
}
|
||||
|
||||
// AssertNoError helper to assert no error on result
|
||||
func (c *KnRunResultCollector) AssertNoError(result KnRunResult) {
|
||||
c.results = append(c.results, result)
|
||||
|
|
|
|||
|
|
@ -35,42 +35,44 @@ func TestBasicWorkflow(t *testing.T) {
|
|||
assert.NilError(t, it.Teardown())
|
||||
}()
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
t.Log("returns no service before running tests")
|
||||
serviceListEmpty(t, it, r)
|
||||
serviceListEmpty(r)
|
||||
|
||||
t.Log("create hello service and return no error")
|
||||
serviceCreate(t, it, r, "hello")
|
||||
serviceCreate(r, "hello")
|
||||
|
||||
t.Log("return valid info about hello service")
|
||||
serviceList(t, it, r, "hello")
|
||||
serviceDescribe(t, it, r, "hello")
|
||||
serviceList(r, "hello")
|
||||
serviceDescribe(r, "hello")
|
||||
|
||||
t.Log("update hello service's configuration and return no error")
|
||||
serviceUpdate(t, it, r, "hello", "--env", "TARGET=kn", "--port", "8888")
|
||||
serviceUpdate(r, "hello", "--env", "TARGET=kn", "--port", "8888")
|
||||
|
||||
t.Log("create another service and return no error")
|
||||
serviceCreate(t, it, r, "svc2")
|
||||
serviceCreate(r, "svc2")
|
||||
|
||||
t.Log("return a list of revisions associated with hello and svc2 services")
|
||||
revisionListForService(t, it, r, "hello")
|
||||
revisionListForService(t, it, r, "svc2")
|
||||
revisionListForService(r, "hello")
|
||||
revisionListForService(r, "svc2")
|
||||
|
||||
t.Log("describe revision from hello service")
|
||||
revisionDescribe(t, it, r, "hello")
|
||||
revisionDescribe(r, "hello")
|
||||
|
||||
t.Log("delete hello and svc2 services and return no error")
|
||||
serviceDelete(t, it, r, "hello")
|
||||
serviceDelete(t, it, r, "svc2")
|
||||
serviceDelete(r, "hello")
|
||||
serviceDelete(r, "svc2")
|
||||
|
||||
t.Log("return no service after completing tests")
|
||||
serviceListEmpty(t, it, r)
|
||||
serviceListEmpty(r)
|
||||
}
|
||||
|
||||
func TestWrongCommand(t *testing.T) {
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
it, err := test.NewKnTest()
|
||||
assert.NilError(t, err)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
out := test.Kn{}.Run("source", "apiserver", "noverb", "--tag=0.13")
|
||||
|
|
@ -85,62 +87,62 @@ func TestWrongCommand(t *testing.T) {
|
|||
|
||||
// ==========================================================================
|
||||
|
||||
func serviceListEmpty(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector) {
|
||||
out := it.Kn().Run("service", "list")
|
||||
func serviceListEmpty(r *test.KnRunResultCollector) {
|
||||
out := r.KnTest().Kn().Run("service", "list")
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, "No services found."))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, "No services found."))
|
||||
}
|
||||
|
||||
func serviceCreate(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string) {
|
||||
out := it.Kn().Run("service", "create", serviceName, "--image", test.KnDefaultTestImage)
|
||||
func serviceCreate(r *test.KnRunResultCollector, serviceName string) {
|
||||
out := r.KnTest().Kn().Run("service", "create", serviceName, "--image", test.KnDefaultTestImage)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "service", serviceName, "creating", "namespace", it.Kn().Namespace(), "ready"))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "service", serviceName, "creating", "namespace", r.KnTest().Kn().Namespace(), "ready"))
|
||||
}
|
||||
|
||||
func serviceList(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string) {
|
||||
out := it.Kn().Run("service", "list", serviceName)
|
||||
func serviceList(r *test.KnRunResultCollector, serviceName string) {
|
||||
out := r.KnTest().Kn().Run("service", "list", serviceName)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, serviceName))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, serviceName))
|
||||
}
|
||||
|
||||
func serviceDescribe(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string) {
|
||||
out := it.Kn().Run("service", "describe", serviceName)
|
||||
func serviceDescribe(r *test.KnRunResultCollector, serviceName string) {
|
||||
out := r.KnTest().Kn().Run("service", "describe", serviceName)
|
||||
r.AssertNoError(out)
|
||||
assert.Assert(t, util.ContainsAll(out.Stdout, serviceName, it.Kn().Namespace(), test.KnDefaultTestImage))
|
||||
assert.Assert(t, util.ContainsAll(out.Stdout, "Conditions", "ConfigurationsReady", "Ready", "RoutesReady"))
|
||||
assert.Assert(t, util.ContainsAll(out.Stdout, "Name", "Namespace", "URL", "Age", "Revisions"))
|
||||
assert.Assert(r.T(), util.ContainsAll(out.Stdout, serviceName, r.KnTest().Kn().Namespace(), test.KnDefaultTestImage))
|
||||
assert.Assert(r.T(), util.ContainsAll(out.Stdout, "Conditions", "ConfigurationsReady", "Ready", "RoutesReady"))
|
||||
assert.Assert(r.T(), util.ContainsAll(out.Stdout, "Name", "Namespace", "URL", "Age", "Revisions"))
|
||||
}
|
||||
|
||||
func serviceUpdate(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string, args ...string) {
|
||||
func serviceUpdate(r *test.KnRunResultCollector, serviceName string, args ...string) {
|
||||
fullArgs := append([]string{}, "service", "update", serviceName)
|
||||
fullArgs = append(fullArgs, args...)
|
||||
out := it.Kn().Run(fullArgs...)
|
||||
out := r.KnTest().Kn().Run(fullArgs...)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "updating", "service", serviceName, "ready"))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "updating", "service", serviceName, "ready"))
|
||||
}
|
||||
|
||||
func serviceDelete(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string) {
|
||||
out := it.Kn().Run("service", "delete", serviceName)
|
||||
func serviceDelete(r *test.KnRunResultCollector, serviceName string) {
|
||||
out := r.KnTest().Kn().Run("service", "delete", serviceName)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, "Service", serviceName, "successfully deleted in namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, "Service", serviceName, "successfully deleted in namespace", r.KnTest().Kn().Namespace()))
|
||||
}
|
||||
|
||||
func revisionListForService(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string) {
|
||||
out := it.Kn().Run("revision", "list", "-s", serviceName)
|
||||
func revisionListForService(r *test.KnRunResultCollector, serviceName string) {
|
||||
out := r.KnTest().Kn().Run("revision", "list", "-s", serviceName)
|
||||
r.AssertNoError(out)
|
||||
outputLines := strings.Split(out.Stdout, "\n")
|
||||
// Ignore the last line because it is an empty string caused by splitting a line break
|
||||
// at the end of the output string
|
||||
for _, line := range outputLines[1 : len(outputLines)-1] {
|
||||
// The last item is the revision status, which should be ready
|
||||
assert.Check(t, util.ContainsAll(line, " "+serviceName+" ", "True"))
|
||||
assert.Check(r.T(), util.ContainsAll(line, " "+serviceName+" ", "True"))
|
||||
}
|
||||
}
|
||||
|
||||
func revisionDescribe(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string) {
|
||||
revName := findRevision(t, it, r, serviceName)
|
||||
func revisionDescribe(r *test.KnRunResultCollector, serviceName string) {
|
||||
revName := findRevision(r, serviceName)
|
||||
|
||||
out := it.Kn().Run("revision", "describe", revName)
|
||||
out := r.KnTest().Kn().Run("revision", "describe", revName)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, revName, it.Kn().Namespace(), serviceName, "++ Ready", "TARGET=kn"))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, revName, r.KnTest().Kn().Namespace(), serviceName, "++ Ready", "TARGET=kn"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,26 +34,26 @@ func TestSourcePing(t *testing.T) {
|
|||
assert.NilError(t, it.Teardown())
|
||||
}()
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
t.Log("Creating a testservice")
|
||||
serviceCreate(t, it, r, "testsvc0")
|
||||
serviceCreate(r, "testsvc0")
|
||||
|
||||
t.Log("create Ping sources with a sink to a service")
|
||||
|
||||
pingSourceCreate(t, it, r, "testpingsource0", "* * * * */1", "ping", "svc:testsvc0")
|
||||
pingSourceCreate(r, "testpingsource0", "* * * * */1", "ping", "svc:testsvc0")
|
||||
|
||||
t.Log("delete Ping sources")
|
||||
pingSourceDelete(t, it, r, "testpingsource0")
|
||||
pingSourceDelete(r, "testpingsource0")
|
||||
|
||||
t.Log("create Ping source with a missing sink service")
|
||||
pingSourceCreateMissingSink(t, it, r, "testpingsource1", "* * * * */1", "ping", "svc:unknown")
|
||||
pingSourceCreateMissingSink(r, "testpingsource1", "* * * * */1", "ping", "svc:unknown")
|
||||
|
||||
t.Log("update Ping source sink service")
|
||||
pingSourceCreate(t, it, r, "testpingsource2", "* * * * */1", "ping", "svc:testsvc0")
|
||||
serviceCreate(t, it, r, "testsvc1")
|
||||
pingSourceUpdateSink(t, it, r, "testpingsource2", "svc:testsvc1")
|
||||
pingSourceCreate(r, "testpingsource2", "* * * * */1", "ping", "svc:testsvc0")
|
||||
serviceCreate(r, "testsvc1")
|
||||
pingSourceUpdateSink(r, "testpingsource2", "svc:testsvc1")
|
||||
jpSinkRefNameInSpec := "jsonpath={.spec.sink.ref.name}"
|
||||
out, err := getResourceFieldsWithJSONPath(t, it, "pingsource", "testpingsource2", jpSinkRefNameInSpec)
|
||||
assert.NilError(t, err)
|
||||
|
|
@ -61,54 +61,54 @@ func TestSourcePing(t *testing.T) {
|
|||
|
||||
t.Log("verify Ping source description")
|
||||
mymsg := "This is a message from Ping."
|
||||
pingSourceCreate(t, it, r, "testpingsource3", "*/1 * * * *", mymsg, "svc:testsvc1")
|
||||
verifyPingSourceDescribe(t, it, r, "testpingsource3", "*/1 * * * *", mymsg, "testsvc1")
|
||||
pingSourceCreate(r, "testpingsource3", "*/1 * * * *", mymsg, "svc:testsvc1")
|
||||
verifyPingSourceDescribe(r, "testpingsource3", "*/1 * * * *", mymsg, "testsvc1")
|
||||
}
|
||||
|
||||
func pingSourceCreate(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, sourceName string, schedule string, data string, sink string) {
|
||||
out := it.Kn().Run("source", "ping", "create", sourceName,
|
||||
func pingSourceCreate(r *test.KnRunResultCollector, sourceName string, schedule string, data string, sink string) {
|
||||
out := r.KnTest().Kn().Run("source", "ping", "create", sourceName,
|
||||
"--schedule", schedule, "--data", data, "--sink", sink)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "ping", "source", sourceName, "created", "namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "ping", "source", sourceName, "created", "namespace", r.KnTest().Kn().Namespace()))
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func pingSourceDelete(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, sourceName string) {
|
||||
out := it.Kn().Run("source", "ping", "delete", sourceName)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "ping", "source", sourceName, "deleted", "namespace", it.Kn().Namespace()))
|
||||
func pingSourceDelete(r *test.KnRunResultCollector, sourceName string) {
|
||||
out := r.KnTest().Kn().Run("source", "ping", "delete", sourceName)
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "ping", "source", sourceName, "deleted", "namespace", r.KnTest().Kn().Namespace()))
|
||||
r.AssertNoError(out)
|
||||
|
||||
}
|
||||
|
||||
func pingSourceCreateMissingSink(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, sourceName string, schedule string, data string, sink string) {
|
||||
out := it.Kn().Run("source", "ping", "create", sourceName,
|
||||
func pingSourceCreateMissingSink(r *test.KnRunResultCollector, sourceName string, schedule string, data string, sink string) {
|
||||
out := r.KnTest().Kn().Run("source", "ping", "create", sourceName,
|
||||
"--schedule", schedule, "--data", data, "--sink", sink)
|
||||
assert.Check(t, util.ContainsAll(out.Stderr, "services.serving.knative.dev", "not found"))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stderr, "services.serving.knative.dev", "not found"))
|
||||
r.AssertError(out)
|
||||
}
|
||||
|
||||
func pingSourceUpdateSink(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, sourceName string, sink string) {
|
||||
out := it.Kn().Run("source", "ping", "update", sourceName, "--sink", sink)
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, sourceName, "updated", "namespace", it.Kn().Namespace()))
|
||||
func pingSourceUpdateSink(r *test.KnRunResultCollector, sourceName string, sink string) {
|
||||
out := r.KnTest().Kn().Run("source", "ping", "update", sourceName, "--sink", sink)
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, sourceName, "updated", "namespace", r.KnTest().Kn().Namespace()))
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func pingSourceCreateWithResources(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, sourceName string, schedule string, data string, sink string, sa string, requestcpu string, requestmm string, limitcpu string, limitmm string) {
|
||||
out := it.Kn().Run("source", "ping", "create", sourceName,
|
||||
func pingSourceCreateWithResources(r *test.KnRunResultCollector, sourceName string, schedule string, data string, sink string, sa string, requestcpu string, requestmm string, limitcpu string, limitmm string) {
|
||||
out := r.KnTest().Kn().Run("source", "ping", "create", sourceName,
|
||||
"--schedule", schedule, "--data", data, "--sink", sink, "--service-account", sa,
|
||||
"--requests-cpu", requestcpu, "--requests-memory", requestmm, "--limits-cpu", limitcpu, "--limits-memory", limitmm)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "ping", "source", sourceName, "created", "namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "ping", "source", sourceName, "created", "namespace", r.KnTest().Kn().Namespace()))
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func pingSourceUpdateResources(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, sourceName string, requestcpu string, requestmm string, limitcpu string, limitmm string) {
|
||||
out := it.Kn().Run("source", "ping", "update", sourceName,
|
||||
func pingSourceUpdateResources(r *test.KnRunResultCollector, sourceName string, requestcpu string, requestmm string, limitcpu string, limitmm string) {
|
||||
out := r.KnTest().Kn().Run("source", "ping", "update", sourceName,
|
||||
"--requests-cpu", requestcpu, "--requests-memory", requestmm, "--limits-cpu", limitcpu, "--limits-memory", limitmm)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, sourceName, "updated", "namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, sourceName, "updated", "namespace", r.KnTest().Kn().Namespace()))
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func verifyPingSourceDescribe(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, sourceName string, schedule string, data string, sink string) {
|
||||
out := it.Kn().Run("source", "ping", "describe", sourceName)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, sourceName, schedule, data, sink))
|
||||
func verifyPingSourceDescribe(r *test.KnRunResultCollector, sourceName string, schedule string, data string, sink string) {
|
||||
out := r.KnTest().Kn().Run("source", "ping", "describe", sourceName)
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, sourceName, schedule, data, sink))
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,26 +96,31 @@ func TestPluginWithoutLookup(t *testing.T) {
|
|||
pc, oldPath := setupPluginTestConfigWithNewPath(t)
|
||||
defer tearDownWithPath(pc, oldPath)
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
it, err := test.NewKnTest()
|
||||
assert.NilError(t, err)
|
||||
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir), "--lookup-plugins=false"}
|
||||
|
||||
t.Log("list plugin in --plugins-dir")
|
||||
listPlugin(t, r, knFlags, []string{pc.knPluginPath}, []string{})
|
||||
listPlugin(r, knFlags, []string{pc.knPluginPath}, []string{})
|
||||
|
||||
t.Log("execute plugin in --plugins-dir")
|
||||
runPlugin(t, r, knFlags, "helloe2e", []string{"e2e", "test"}, []string{"Hello Knative, I'm a Kn plugin", "I received arguments: e2e"})
|
||||
runPlugin(r, knFlags, "helloe2e", []string{"e2e", "test"}, []string{"Hello Knative, I'm a Kn plugin", "I received arguments: e2e"})
|
||||
|
||||
t.Log("does not list any other plugin in $PATH")
|
||||
listPlugin(t, r, knFlags, []string{pc.knPluginPath}, []string{pc.knPluginPath2})
|
||||
listPlugin(r, knFlags, []string{pc.knPluginPath}, []string{pc.knPluginPath2})
|
||||
|
||||
t.Log("with --lookup-plugins is true")
|
||||
}
|
||||
|
||||
func TestPluginWithLookup(t *testing.T) {
|
||||
it, err := test.NewKnTest()
|
||||
assert.NilError(t, err)
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
pc := pluginTestConfig{}
|
||||
|
|
@ -125,28 +130,33 @@ func TestPluginWithLookup(t *testing.T) {
|
|||
knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir), "--lookup-plugins=true"}
|
||||
|
||||
t.Log("list plugin in --plugins-dir")
|
||||
listPlugin(t, r, knFlags, []string{pc.knPluginPath}, []string{pc.knPluginPath2})
|
||||
listPlugin(r, knFlags, []string{pc.knPluginPath}, []string{pc.knPluginPath2})
|
||||
|
||||
t.Log("execute plugin in --plugins-dir")
|
||||
runPlugin(t, r, knFlags, "helloe2e", []string{}, []string{"Hello Knative, I'm a Kn plugin"})
|
||||
runPlugin(r, knFlags, "helloe2e", []string{}, []string{"Hello Knative, I'm a Kn plugin"})
|
||||
}
|
||||
|
||||
func TestListPluginInPath(t *testing.T) {
|
||||
it, err := test.NewKnTest()
|
||||
assert.NilError(t, err)
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
|
||||
pc, oldPath := setupPluginTestConfigWithNewPath(t)
|
||||
defer tearDownWithPath(pc, oldPath)
|
||||
|
||||
t.Log("list plugin in $PATH")
|
||||
knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir), "--lookup-plugins=true"}
|
||||
listPlugin(t, r, knFlags, []string{pc.knPluginPath, pc.knPluginPath2}, []string{})
|
||||
listPlugin(r, knFlags, []string{pc.knPluginPath, pc.knPluginPath2}, []string{})
|
||||
|
||||
r.DumpIfFailed()
|
||||
}
|
||||
|
||||
func TestExecutePluginInPath(t *testing.T) {
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
it, err := test.NewKnTest()
|
||||
assert.NilError(t, err)
|
||||
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
pc, oldPath := setupPluginTestConfigWithNewPath(t)
|
||||
|
|
@ -154,7 +164,7 @@ func TestExecutePluginInPath(t *testing.T) {
|
|||
|
||||
t.Log("execute plugin in $PATH")
|
||||
knFlags := []string{fmt.Sprintf("--plugins-dir=%s", pc.knPluginsDir), "--lookup-plugins=true"}
|
||||
runPlugin(t, r, knFlags, "hello2e2e", []string{}, []string{"Hello Knative, I'm a Kn plugin"})
|
||||
runPlugin(r, knFlags, "hello2e2e", []string{}, []string{"Hello Knative, I'm a Kn plugin"})
|
||||
}
|
||||
|
||||
func setupPluginTestConfigWithNewPath(t *testing.T) (pluginTestConfig, string) {
|
||||
|
|
@ -172,16 +182,16 @@ func tearDownWithPath(pc pluginTestConfig, oldPath string) {
|
|||
|
||||
// Private
|
||||
|
||||
func listPlugin(t *testing.T, r *test.KnRunResultCollector, knFlags []string, expectedPlugins []string, unexpectedPlugins []string) {
|
||||
func listPlugin(r *test.KnRunResultCollector, knFlags []string, expectedPlugins []string, unexpectedPlugins []string) {
|
||||
knArgs := append(knFlags, "plugin", "list")
|
||||
|
||||
out := test.Kn{}.Run(knArgs...)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, expectedPlugins...))
|
||||
assert.Check(t, util.ContainsNone(out.Stdout, unexpectedPlugins...))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, expectedPlugins...))
|
||||
assert.Check(r.T(), util.ContainsNone(out.Stdout, unexpectedPlugins...))
|
||||
}
|
||||
|
||||
func runPlugin(t *testing.T, r *test.KnRunResultCollector, knFlags []string, pluginName string, args []string, expectedOutput []string) {
|
||||
func runPlugin(r *test.KnRunResultCollector, knFlags []string, pluginName string, args []string, expectedOutput []string) {
|
||||
knArgs := append([]string{}, knFlags...)
|
||||
knArgs = append(knArgs, pluginName)
|
||||
knArgs = append(knArgs, args...)
|
||||
|
|
@ -189,6 +199,6 @@ func runPlugin(t *testing.T, r *test.KnRunResultCollector, knFlags []string, plu
|
|||
out := test.Kn{}.Run(knArgs...)
|
||||
r.AssertNoError(out)
|
||||
for _, output := range expectedOutput {
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, output))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, output))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,115 +37,115 @@ func TestRevision(t *testing.T) {
|
|||
assert.NilError(t, it.Teardown())
|
||||
}()
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
t.Log("create hello service and return no error")
|
||||
serviceCreate(t, it, r, "hello")
|
||||
serviceCreate(r, "hello")
|
||||
|
||||
t.Log("describe revision from hello service with print flags")
|
||||
revName := findRevision(t, it, r, "hello")
|
||||
revisionDescribeWithPrintFlags(t, it, r, revName)
|
||||
revName := findRevision(r, "hello")
|
||||
revisionDescribeWithPrintFlags(r, revName)
|
||||
|
||||
t.Log("update hello service and increase revision count to 2")
|
||||
serviceUpdate(t, it, r, "hello", "--env", "TARGET=kn", "--port", "8888")
|
||||
serviceUpdate(r, "hello", "--env", "TARGET=kn", "--port", "8888")
|
||||
|
||||
t.Log("show a list of revisions sorted by the count of configuration generation")
|
||||
revisionListWithService(t, it, r, "hello")
|
||||
revisionListWithService(r, "hello")
|
||||
|
||||
t.Log("update hello service and increase revision count to 3")
|
||||
serviceUpdate(t, it, r, "hello", "--env", "TARGET=kn", "--port", "8888")
|
||||
serviceUpdate(r, "hello", "--env", "TARGET=kn", "--port", "8888")
|
||||
|
||||
t.Log("delete three revisions with one revision a nonexistent")
|
||||
existRevision1 := findRevisionByGeneration(t, it, r, "hello", 1)
|
||||
existRevision2 := findRevisionByGeneration(t, it, r, "hello", 2)
|
||||
existRevision1 := findRevisionByGeneration(r, "hello", 1)
|
||||
existRevision2 := findRevisionByGeneration(r, "hello", 2)
|
||||
nonexistRevision := "hello-nonexist"
|
||||
revisionMultipleDelete(t, it, r, existRevision1, existRevision2, nonexistRevision)
|
||||
revisionMultipleDelete(r, existRevision1, existRevision2, nonexistRevision)
|
||||
|
||||
t.Log("delete latest revision from hello service and return no error")
|
||||
revName = findRevision(t, it, r, "hello")
|
||||
revisionDelete(t, it, r, revName)
|
||||
revName = findRevision(r, "hello")
|
||||
revisionDelete(r, revName)
|
||||
|
||||
t.Log("delete hello service and return no error")
|
||||
serviceDelete(t, it, r, "hello")
|
||||
serviceDelete(r, "hello")
|
||||
}
|
||||
|
||||
func revisionListWithService(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceNames ...string) {
|
||||
func revisionListWithService(r *test.KnRunResultCollector, serviceNames ...string) {
|
||||
for _, svcName := range serviceNames {
|
||||
confGen := findConfigurationGeneration(t, it, r, svcName)
|
||||
out := it.Kn().Run("revision", "list", "-s", svcName)
|
||||
confGen := findConfigurationGeneration(r, svcName)
|
||||
out := r.KnTest().Kn().Run("revision", "list", "-s", svcName)
|
||||
r.AssertNoError(out)
|
||||
|
||||
outputLines := strings.Split(out.Stdout, "\n")
|
||||
// Ignore the last line because it is an empty string caused by splitting a line break
|
||||
// at the end of the output string
|
||||
for _, line := range outputLines[1 : len(outputLines)-1] {
|
||||
revName := findRevisionByGeneration(t, it, r, svcName, confGen)
|
||||
assert.Check(t, util.ContainsAll(line, revName, svcName, strconv.Itoa(confGen)))
|
||||
revName := findRevisionByGeneration(r, svcName, confGen)
|
||||
assert.Check(r.T(), util.ContainsAll(line, revName, svcName, strconv.Itoa(confGen)))
|
||||
confGen--
|
||||
}
|
||||
if t.Failed() {
|
||||
r.AddDump("service", svcName, it.Kn().Namespace())
|
||||
if r.T().Failed() {
|
||||
r.AddDump("service", svcName, r.KnTest().Kn().Namespace())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func revisionDelete(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, revName string) {
|
||||
out := it.Kn().Run("revision", "delete", revName)
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, "Revision", revName, "deleted", "namespace", it.Kn().Namespace()))
|
||||
func revisionDelete(r *test.KnRunResultCollector, revName string) {
|
||||
out := r.KnTest().Kn().Run("revision", "delete", revName)
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, "Revision", revName, "deleted", "namespace", r.KnTest().Kn().Namespace()))
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func revisionMultipleDelete(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, existRevision1, existRevision2, nonexistRevision string) {
|
||||
out := it.Kn().Run("revision", "list")
|
||||
func revisionMultipleDelete(r *test.KnRunResultCollector, existRevision1, existRevision2, nonexistRevision string) {
|
||||
out := r.KnTest().Kn().Run("revision", "list")
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, strings.Contains(out.Stdout, existRevision1), "Required revision1 does not exist")
|
||||
assert.Check(t, strings.Contains(out.Stdout, existRevision2), "Required revision2 does not exist")
|
||||
assert.Check(r.T(), strings.Contains(out.Stdout, existRevision1), "Required revision1 does not exist")
|
||||
assert.Check(r.T(), strings.Contains(out.Stdout, existRevision2), "Required revision2 does not exist")
|
||||
|
||||
out = it.Kn().Run("revision", "delete", existRevision1, existRevision2, nonexistRevision)
|
||||
out = r.KnTest().Kn().Run("revision", "delete", existRevision1, existRevision2, nonexistRevision)
|
||||
r.AssertNoError(out)
|
||||
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, "Revision", existRevision1, "deleted", "namespace", it.Kn().Namespace()), "Failed to get 'deleted' first revision message")
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, "Revision", existRevision2, "deleted", "namespace", it.Kn().Namespace()), "Failed to get 'deleted' second revision message")
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, "revisions.serving.knative.dev", nonexistRevision, "not found"), "Failed to get 'not found' error")
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, "Revision", existRevision1, "deleted", "namespace", r.KnTest().Kn().Namespace()), "Failed to get 'deleted' first revision message")
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, "Revision", existRevision2, "deleted", "namespace", r.KnTest().Kn().Namespace()), "Failed to get 'deleted' second revision message")
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, "revisions.serving.knative.dev", nonexistRevision, "not found"), "Failed to get 'not found' error")
|
||||
}
|
||||
|
||||
func revisionDescribeWithPrintFlags(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, revName string) {
|
||||
out := it.Kn().Run("revision", "describe", revName, "-o=name")
|
||||
func revisionDescribeWithPrintFlags(r *test.KnRunResultCollector, revName string) {
|
||||
out := r.KnTest().Kn().Run("revision", "describe", revName, "-o=name")
|
||||
r.AssertNoError(out)
|
||||
expectedName := fmt.Sprintf("revision.serving.knative.dev/%s", revName)
|
||||
assert.Equal(t, strings.TrimSpace(out.Stdout), expectedName)
|
||||
assert.Equal(r.T(), strings.TrimSpace(out.Stdout), expectedName)
|
||||
}
|
||||
|
||||
func findRevision(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string) string {
|
||||
out := it.Kn().Run("revision", "list", "-s", serviceName, "-o=jsonpath={.items[0].metadata.name}")
|
||||
func findRevision(r *test.KnRunResultCollector, serviceName string) string {
|
||||
out := r.KnTest().Kn().Run("revision", "list", "-s", serviceName, "-o=jsonpath={.items[0].metadata.name}")
|
||||
r.AssertNoError(out)
|
||||
if strings.Contains(out.Stdout, "No resources") {
|
||||
t.Errorf("Could not find revision name.")
|
||||
r.T().Errorf("Could not find revision name.")
|
||||
}
|
||||
return out.Stdout
|
||||
}
|
||||
|
||||
func findRevisionByGeneration(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string, generation int) string {
|
||||
maxGen := findConfigurationGeneration(t, it, r, serviceName)
|
||||
out := it.Kn().Run("revision", "list", "-s", serviceName,
|
||||
func findRevisionByGeneration(r *test.KnRunResultCollector, serviceName string, generation int) string {
|
||||
maxGen := findConfigurationGeneration(r, serviceName)
|
||||
out := r.KnTest().Kn().Run("revision", "list", "-s", serviceName,
|
||||
fmt.Sprintf("-o=jsonpath={.items[%d].metadata.name}", maxGen-generation))
|
||||
r.AssertNoError(out)
|
||||
if strings.Contains(out.Stdout, "No resources found.") {
|
||||
t.Errorf("Could not find revision name.")
|
||||
r.T().Errorf("Could not find revision name.")
|
||||
}
|
||||
return out.Stdout
|
||||
}
|
||||
|
||||
func findConfigurationGeneration(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string) int {
|
||||
out := it.Kn().Run("revision", "list", "-s", serviceName, "-o=jsonpath={.items[0].metadata.labels.serving\\.knative\\.dev/configurationGeneration}")
|
||||
func findConfigurationGeneration(r *test.KnRunResultCollector, serviceName string) int {
|
||||
out := r.KnTest().Kn().Run("revision", "list", "-s", serviceName, "-o=jsonpath={.items[0].metadata.labels.serving\\.knative\\.dev/configurationGeneration}")
|
||||
r.AssertNoError(out)
|
||||
if out.Stdout == "" {
|
||||
t.Errorf("Could not find configuration generation.")
|
||||
r.T().Errorf("Could not find configuration generation.")
|
||||
}
|
||||
confGen, err := strconv.Atoi(out.Stdout)
|
||||
if err != nil {
|
||||
t.Errorf("Invalid type of configuration generation: %s", err)
|
||||
r.T().Errorf("Invalid type of configuration generation: %s", err)
|
||||
}
|
||||
|
||||
return confGen
|
||||
|
|
|
|||
|
|
@ -36,64 +36,64 @@ func TestRoute(t *testing.T) {
|
|||
assert.NilError(t, it.Teardown())
|
||||
}()
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
t.Log("create hello service and return no error")
|
||||
serviceCreate(t, it, r, "hello")
|
||||
serviceCreate(r, "hello")
|
||||
|
||||
t.Log("return a list of routes")
|
||||
routeList(t, it, r)
|
||||
routeList(r)
|
||||
|
||||
t.Log("return a list of routes associated with hello service")
|
||||
routeListWithArgument(t, it, r, "hello")
|
||||
routeListWithArgument(r, "hello")
|
||||
|
||||
t.Log("return a list of routes associated with hello service with print flags")
|
||||
routeListWithPrintFlags(t, it, r, "hello")
|
||||
routeListWithPrintFlags(r, "hello")
|
||||
|
||||
t.Log("describe route from hello service")
|
||||
routeDescribe(t, it, r, "hello")
|
||||
routeDescribe(r, "hello")
|
||||
|
||||
t.Log("describe route from hello service with print flags")
|
||||
routeDescribeWithPrintFlags(t, it, r, "hello")
|
||||
routeDescribeWithPrintFlags(r, "hello")
|
||||
|
||||
t.Log("delete hello service and return no error")
|
||||
serviceDelete(t, it, r, "hello")
|
||||
serviceDelete(r, "hello")
|
||||
}
|
||||
|
||||
func routeList(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector) {
|
||||
out := it.Kn().Run("route", "list")
|
||||
func routeList(r *test.KnRunResultCollector) {
|
||||
out := r.KnTest().Kn().Run("route", "list")
|
||||
|
||||
expectedHeaders := []string{"NAME", "URL", "READY"}
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, expectedHeaders...))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, expectedHeaders...))
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func routeListWithArgument(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, routeName string) {
|
||||
out := it.Kn().Run("route", "list", routeName)
|
||||
func routeListWithArgument(r *test.KnRunResultCollector, routeName string) {
|
||||
out := r.KnTest().Kn().Run("route", "list", routeName)
|
||||
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, routeName))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, routeName))
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func routeDescribe(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, routeName string) {
|
||||
out := it.Kn().Run("route", "describe", routeName)
|
||||
func routeDescribe(r *test.KnRunResultCollector, routeName string) {
|
||||
out := r.KnTest().Kn().Run("route", "describe", routeName)
|
||||
|
||||
assert.Check(t, util.ContainsAll(out.Stdout,
|
||||
routeName, it.Kn().Namespace(), "URL", "Service", "Traffic", "Targets", "Conditions"))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout,
|
||||
routeName, r.KnTest().Kn().Namespace(), "URL", "Service", "Traffic", "Targets", "Conditions"))
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func routeDescribeWithPrintFlags(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, routeName string) {
|
||||
out := it.Kn().Run("route", "describe", routeName, "-o=name")
|
||||
func routeDescribeWithPrintFlags(r *test.KnRunResultCollector, routeName string) {
|
||||
out := r.KnTest().Kn().Run("route", "describe", routeName, "-o=name")
|
||||
|
||||
expectedName := fmt.Sprintf("route.serving.knative.dev/%s", routeName)
|
||||
assert.Equal(t, strings.TrimSpace(out.Stdout), expectedName)
|
||||
assert.Equal(r.T(), strings.TrimSpace(out.Stdout), expectedName)
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func routeListWithPrintFlags(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, names ...string) {
|
||||
out := it.Kn().Run("route", "list", "-o=jsonpath={.items[*].metadata.name}")
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, names...))
|
||||
func routeListWithPrintFlags(r *test.KnRunResultCollector, names ...string) {
|
||||
out := r.KnTest().Kn().Run("route", "list", "-o=jsonpath={.items[*].metadata.name}")
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, names...))
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,45 +44,45 @@ func TestServiceExportImportApply(t *testing.T) {
|
|||
assert.NilError(t, it.Teardown())
|
||||
}()
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
t.Log("create service with byo revision")
|
||||
serviceCreateWithOptions(t, it, r, "hello", "--revision-name", "rev1")
|
||||
serviceCreateWithOptions(r, "hello", "--revision-name", "rev1")
|
||||
|
||||
t.Log("export service and compare")
|
||||
serviceExport(t, it, r, "hello", getSvc(withName("hello"), withRevisionName("hello-rev1"), withAnnotations()), "-o", "json")
|
||||
serviceExport(r, "hello", getSvc(withName("hello"), withRevisionName("hello-rev1"), withAnnotations()), "-o", "json")
|
||||
|
||||
t.Log("update service - add env variable")
|
||||
serviceUpdateWithOptions(t, it, r, "hello", "--env", "key1=val1", "--revision-name", "rev2", "--no-lock-to-digest")
|
||||
serviceExport(t, it, r, "hello", getSvc(withName("hello"), withRevisionName("hello-rev2"), withEnv("key1", "val1")), "-o", "json")
|
||||
serviceExportWithRevisions(t, it, r, "hello", getSvcListWithOneRevision(), "--with-revisions", "-o", "yaml")
|
||||
serviceUpdateWithOptions(r, "hello", "--env", "key1=val1", "--revision-name", "rev2", "--no-lock-to-digest")
|
||||
serviceExport(r, "hello", getSvc(withName("hello"), withRevisionName("hello-rev2"), withEnv("key1", "val1")), "-o", "json")
|
||||
serviceExportWithRevisions(r, "hello", getSvcListWithOneRevision(), "--with-revisions", "-o", "yaml")
|
||||
|
||||
t.Log("update service with tag and split traffic")
|
||||
serviceUpdateWithOptions(t, it, r, "hello", "--tag", "hello-rev1=candidate", "--traffic", "candidate=2%,@latest=98%")
|
||||
serviceExportWithRevisions(t, it, r, "hello", getSvcListWithTags(), "--with-revisions", "-o", "yaml")
|
||||
serviceUpdateWithOptions(r, "hello", "--tag", "hello-rev1=candidate", "--traffic", "candidate=2%,@latest=98%")
|
||||
serviceExportWithRevisions(r, "hello", getSvcListWithTags(), "--with-revisions", "-o", "yaml")
|
||||
|
||||
t.Log("update service - untag, add env variable and traffic split")
|
||||
serviceUpdateWithOptions(t, it, r, "hello", "--untag", "candidate")
|
||||
serviceUpdateWithOptions(t, it, r, "hello", "--env", "key2=val2", "--revision-name", "rev3", "--traffic", "hello-rev1=30,hello-rev2=30,hello-rev3=40")
|
||||
serviceExportWithRevisions(t, it, r, "hello", getSvcListWOTags(), "--with-revisions", "-o", "yaml")
|
||||
serviceUpdateWithOptions(r, "hello", "--untag", "candidate")
|
||||
serviceUpdateWithOptions(r, "hello", "--env", "key2=val2", "--revision-name", "rev3", "--traffic", "hello-rev1=30,hello-rev2=30,hello-rev3=40")
|
||||
serviceExportWithRevisions(r, "hello", getSvcListWOTags(), "--with-revisions", "-o", "yaml")
|
||||
}
|
||||
|
||||
// Private methods
|
||||
|
||||
func serviceExport(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string, expService servingv1.Service, options ...string) {
|
||||
func serviceExport(r *test.KnRunResultCollector, serviceName string, expService servingv1.Service, options ...string) {
|
||||
command := []string{"service", "export", serviceName}
|
||||
command = append(command, options...)
|
||||
out := it.Kn().Run(command...)
|
||||
validateExportedService(t, it, out.Stdout, expService)
|
||||
out := r.KnTest().Kn().Run(command...)
|
||||
validateExportedService(r.T(), r.KnTest(), out.Stdout, expService)
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func serviceExportWithRevisions(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string, expServiceList servingv1.ServiceList, options ...string) {
|
||||
func serviceExportWithRevisions(r *test.KnRunResultCollector, serviceName string, expServiceList servingv1.ServiceList, options ...string) {
|
||||
command := []string{"service", "export", serviceName}
|
||||
command = append(command, options...)
|
||||
out := it.Kn().Run(command...)
|
||||
validateExportedServiceList(t, it, out.Stdout, expServiceList)
|
||||
out := r.KnTest().Kn().Run(command...)
|
||||
validateExportedServiceList(r.T(), r.KnTest(), out.Stdout, expServiceList)
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,64 +41,64 @@ func TestServiceOptions(t *testing.T) {
|
|||
assert.NilError(t, it.Teardown())
|
||||
}()
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
|
||||
t.Log("create and validate service with concurrency options")
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
serviceCreateWithOptions(t, it, r, "svc1", "--concurrency-limit", "250", "--concurrency-target", "300")
|
||||
validateServiceConcurrencyTarget(t, it, r, "svc1", "300")
|
||||
validateServiceConcurrencyLimit(t, it, r, "svc1", "250")
|
||||
serviceCreateWithOptions(r, "svc1", "--concurrency-limit", "250", "--concurrency-target", "300")
|
||||
validateServiceConcurrencyTarget(r, "svc1", "300")
|
||||
validateServiceConcurrencyLimit(r, "svc1", "250")
|
||||
|
||||
t.Log("update and validate service with concurrency limit")
|
||||
serviceUpdate(t, it, r, "svc1", "--concurrency-limit", "300")
|
||||
validateServiceConcurrencyLimit(t, it, r, "svc1", "300")
|
||||
serviceUpdate(r, "svc1", "--concurrency-limit", "300")
|
||||
validateServiceConcurrencyLimit(r, "svc1", "300")
|
||||
|
||||
t.Log("update concurrency options with invalid values for service")
|
||||
out := it.Kn().Run("service", "update", "svc1", "--concurrency-limit", "-1", "--concurrency-target", "0")
|
||||
out := r.KnTest().Kn().Run("service", "update", "svc1", "--concurrency-limit", "-1", "--concurrency-target", "0")
|
||||
r.AssertError(out)
|
||||
assert.Check(t, util.ContainsAll(out.Stderr, "invalid"))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stderr, "invalid"))
|
||||
|
||||
t.Log("returns steady concurrency options for service")
|
||||
validateServiceConcurrencyLimit(t, it, r, "svc1", "300")
|
||||
validateServiceConcurrencyTarget(t, it, r, "svc1", "300")
|
||||
validateServiceConcurrencyLimit(r, "svc1", "300")
|
||||
validateServiceConcurrencyTarget(r, "svc1", "300")
|
||||
|
||||
t.Log("delete service")
|
||||
serviceDelete(t, it, r, "svc1")
|
||||
serviceDelete(r, "svc1")
|
||||
|
||||
t.Log("create and validate service with min/max scale options ")
|
||||
serviceCreateWithOptions(t, it, r, "svc2", "--min-scale", "1", "--max-scale", "3")
|
||||
validateServiceMinScale(t, it, r, "svc2", "1")
|
||||
validateServiceMaxScale(t, it, r, "svc2", "3")
|
||||
serviceCreateWithOptions(r, "svc2", "--min-scale", "1", "--max-scale", "3")
|
||||
validateServiceMinScale(r, "svc2", "1")
|
||||
validateServiceMaxScale(r, "svc2", "3")
|
||||
|
||||
t.Log("update and validate service with max scale option")
|
||||
serviceUpdate(t, it, r, "svc2", "--max-scale", "2")
|
||||
validateServiceMaxScale(t, it, r, "svc2", "2")
|
||||
serviceUpdate(r, "svc2", "--max-scale", "2")
|
||||
validateServiceMaxScale(r, "svc2", "2")
|
||||
|
||||
t.Log("delete service")
|
||||
serviceDelete(t, it, r, "svc2")
|
||||
serviceDelete(r, "svc2")
|
||||
|
||||
t.Log("create, update and validate service with annotations")
|
||||
serviceCreateWithOptions(t, it, r, "svc3", "--annotation", "alpha=wolf", "--annotation", "brave=horse")
|
||||
validateServiceAnnotations(t, it, r, "svc3", map[string]string{"alpha": "wolf", "brave": "horse"})
|
||||
serviceUpdate(t, it, r, "svc3", "--annotation", "alpha=direwolf", "--annotation", "brave-")
|
||||
validateServiceAnnotations(t, it, r, "svc3", map[string]string{"alpha": "direwolf", "brave": ""})
|
||||
serviceDelete(t, it, r, "svc3")
|
||||
serviceCreateWithOptions(r, "svc3", "--annotation", "alpha=wolf", "--annotation", "brave=horse")
|
||||
validateServiceAnnotations(r, "svc3", map[string]string{"alpha": "wolf", "brave": "horse"})
|
||||
serviceUpdate(r, "svc3", "--annotation", "alpha=direwolf", "--annotation", "brave-")
|
||||
validateServiceAnnotations(r, "svc3", map[string]string{"alpha": "direwolf", "brave": ""})
|
||||
serviceDelete(r, "svc3")
|
||||
|
||||
t.Log("create, update and validate service with autoscale window option")
|
||||
serviceCreateWithOptions(t, it, r, "svc4", "--autoscale-window", "1m")
|
||||
validateAutoscaleWindow(t, it, r, "svc4", "1m")
|
||||
serviceUpdate(t, it, r, "svc4", "--autoscale-window", "15s")
|
||||
validateAutoscaleWindow(t, it, r, "svc4", "15s")
|
||||
serviceDelete(t, it, r, "svc4")
|
||||
serviceCreateWithOptions(r, "svc4", "--autoscale-window", "1m")
|
||||
validateAutoscaleWindow(r, "svc4", "1m")
|
||||
serviceUpdate(r, "svc4", "--autoscale-window", "15s")
|
||||
validateAutoscaleWindow(r, "svc4", "15s")
|
||||
serviceDelete(r, "svc4")
|
||||
|
||||
t.Log("create, update and validate service with cmd and arg options")
|
||||
serviceCreateWithOptions(t, it, r, "svc5", "--cmd", "/go/bin/helloworld")
|
||||
validateContainerField(t, it, r, "svc5", "command", "[/go/bin/helloworld]")
|
||||
serviceUpdate(t, it, r, "svc5", "--arg", "myArg1", "--arg", "--myArg2")
|
||||
validateContainerField(t, it, r, "svc5", "args", "[myArg1 --myArg2]")
|
||||
serviceUpdate(t, it, r, "svc5", "--arg", "myArg1")
|
||||
validateContainerField(t, it, r, "svc5", "args", "[myArg1]")
|
||||
serviceCreateWithOptions(r, "svc5", "--cmd", "/go/bin/helloworld")
|
||||
validateContainerField(r, "svc5", "command", "[/go/bin/helloworld]")
|
||||
serviceUpdate(r, "svc5", "--arg", "myArg1", "--arg", "--myArg2")
|
||||
validateContainerField(r, "svc5", "args", "[myArg1 --myArg2]")
|
||||
serviceUpdate(r, "svc5", "--arg", "myArg1")
|
||||
validateContainerField(r, "svc5", "args", "[myArg1]")
|
||||
|
||||
t.Log("create, update and validate service with user defined")
|
||||
var uid int64 = 1000
|
||||
|
|
@ -106,83 +106,84 @@ func TestServiceOptions(t *testing.T) {
|
|||
uid, err = strconv.ParseInt(uids, 10, 64)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
serviceCreateWithOptions(t, it, r, "svc6", "--user", strconv.FormatInt(uid, 10))
|
||||
validateUserID(t, it, r, "svc6", uid)
|
||||
serviceUpdate(t, it, r, "svc6", "--user", strconv.FormatInt(uid+1, 10))
|
||||
validateUserID(t, it, r, "svc6", uid+1)
|
||||
|
||||
serviceCreateWithOptions(r, "svc6", "--user", strconv.FormatInt(uid, 10))
|
||||
validateUserID(r, "svc6", uid)
|
||||
serviceUpdate(r, "svc6", "--user", strconv.FormatInt(uid+1, 10))
|
||||
validateUserID(r, "svc6", uid+1)
|
||||
}
|
||||
|
||||
func serviceCreateWithOptions(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string, options ...string) {
|
||||
func serviceCreateWithOptions(r *test.KnRunResultCollector, serviceName string, options ...string) {
|
||||
command := []string{"service", "create", serviceName, "--image", test.KnDefaultTestImage}
|
||||
command = append(command, options...)
|
||||
out := it.Kn().Run(command...)
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, "service", serviceName, "Creating", "namespace", it.Kn().Namespace(), "Ready"))
|
||||
out := r.KnTest().Kn().Run(command...)
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, "service", serviceName, "Creating", "namespace", r.KnTest().Kn().Namespace(), "Ready"))
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func validateServiceConcurrencyLimit(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName, concurrencyLimit string) {
|
||||
func validateServiceConcurrencyLimit(r *test.KnRunResultCollector, serviceName, concurrencyLimit string) {
|
||||
jsonpath := "jsonpath={.items[0].spec.template.spec.containerConcurrency}"
|
||||
out := it.Kn().Run("service", "list", serviceName, "-o", jsonpath)
|
||||
assert.Equal(t, out.Stdout, concurrencyLimit)
|
||||
out := r.KnTest().Kn().Run("service", "list", serviceName, "-o", jsonpath)
|
||||
assert.Equal(r.T(), out.Stdout, concurrencyLimit)
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func validateServiceConcurrencyTarget(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName, concurrencyTarget string) {
|
||||
func validateServiceConcurrencyTarget(r *test.KnRunResultCollector, serviceName, concurrencyTarget string) {
|
||||
jsonpath := "jsonpath={.items[0].spec.template.metadata.annotations.autoscaling\\.knative\\.dev/target}"
|
||||
out := it.Kn().Run("service", "list", serviceName, "-o", jsonpath)
|
||||
assert.Equal(t, out.Stdout, concurrencyTarget)
|
||||
out := r.KnTest().Kn().Run("service", "list", serviceName, "-o", jsonpath)
|
||||
assert.Equal(r.T(), out.Stdout, concurrencyTarget)
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func validateAutoscaleWindow(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName, window string) {
|
||||
func validateAutoscaleWindow(r *test.KnRunResultCollector, serviceName, window string) {
|
||||
jsonpath := "jsonpath={.items[0].spec.template.metadata.annotations.autoscaling\\.knative\\.dev/window}"
|
||||
out := it.Kn().Run("service", "list", serviceName, "-o", jsonpath)
|
||||
assert.Equal(t, out.Stdout, window)
|
||||
out := r.KnTest().Kn().Run("service", "list", serviceName, "-o", jsonpath)
|
||||
assert.Equal(r.T(), out.Stdout, window)
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func validateServiceMinScale(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName, minScale string) {
|
||||
func validateServiceMinScale(r *test.KnRunResultCollector, serviceName, minScale string) {
|
||||
jsonpath := "jsonpath={.items[0].spec.template.metadata.annotations.autoscaling\\.knative\\.dev/minScale}"
|
||||
out := it.Kn().Run("service", "list", serviceName, "-o", jsonpath)
|
||||
assert.Equal(t, out.Stdout, minScale)
|
||||
out := r.KnTest().Kn().Run("service", "list", serviceName, "-o", jsonpath)
|
||||
assert.Equal(r.T(), out.Stdout, minScale)
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func validateServiceMaxScale(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName, maxScale string) {
|
||||
func validateServiceMaxScale(r *test.KnRunResultCollector, serviceName, maxScale string) {
|
||||
jsonpath := "jsonpath={.items[0].spec.template.metadata.annotations.autoscaling\\.knative\\.dev/maxScale}"
|
||||
out := it.Kn().Run("service", "list", serviceName, "-o", jsonpath)
|
||||
assert.Equal(t, out.Stdout, maxScale)
|
||||
out := r.KnTest().Kn().Run("service", "list", serviceName, "-o", jsonpath)
|
||||
assert.Equal(r.T(), out.Stdout, maxScale)
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func validateServiceAnnotations(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string, annotations map[string]string) {
|
||||
func validateServiceAnnotations(r *test.KnRunResultCollector, serviceName string, annotations map[string]string) {
|
||||
metadataAnnotationsJsonpathFormat := "jsonpath={.metadata.annotations.%s}"
|
||||
templateAnnotationsJsonpathFormat := "jsonpath={.spec.template.metadata.annotations.%s}"
|
||||
|
||||
for k, v := range annotations {
|
||||
out := it.Kn().Run("service", "describe", serviceName, "-o", fmt.Sprintf(metadataAnnotationsJsonpathFormat, k))
|
||||
assert.Equal(t, v, out.Stdout)
|
||||
out := r.KnTest().Kn().Run("service", "describe", serviceName, "-o", fmt.Sprintf(metadataAnnotationsJsonpathFormat, k))
|
||||
assert.Equal(r.T(), v, out.Stdout)
|
||||
r.AssertNoError(out)
|
||||
|
||||
out = it.Kn().Run("service", "describe", serviceName, "-o", fmt.Sprintf(templateAnnotationsJsonpathFormat, k))
|
||||
assert.Equal(t, v, out.Stdout)
|
||||
out = r.KnTest().Kn().Run("service", "describe", serviceName, "-o", fmt.Sprintf(templateAnnotationsJsonpathFormat, k))
|
||||
assert.Equal(r.T(), v, out.Stdout)
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
}
|
||||
|
||||
func validateContainerField(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName, field, expected string) {
|
||||
func validateContainerField(r *test.KnRunResultCollector, serviceName, field, expected string) {
|
||||
jsonpath := fmt.Sprintf("jsonpath={.items[0].spec.template.spec.containers[0].%s}", field)
|
||||
out := it.Kn().Run("service", "list", serviceName, "-o", jsonpath)
|
||||
assert.Equal(t, out.Stdout, expected)
|
||||
out := r.KnTest().Kn().Run("service", "list", serviceName, "-o", jsonpath)
|
||||
assert.Equal(r.T(), out.Stdout, expected)
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
||||
func validateUserID(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string, uid int64) {
|
||||
out := it.Kn().Run("service", "describe", serviceName, "-ojson")
|
||||
func validateUserID(r *test.KnRunResultCollector, serviceName string, uid int64) {
|
||||
out := r.KnTest().Kn().Run("service", "describe", serviceName, "-ojson")
|
||||
data := json.NewDecoder(strings.NewReader(out.Stdout))
|
||||
data.UseNumber()
|
||||
var service servingv1.Service
|
||||
err := data.Decode(&service)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, *service.Spec.Template.Spec.Containers[0].SecurityContext.RunAsUser, uid)
|
||||
assert.NilError(r.T(), err)
|
||||
assert.Equal(r.T(), *service.Spec.Template.Spec.Containers[0].SecurityContext.RunAsUser, uid)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,99 +37,99 @@ func TestService(t *testing.T) {
|
|||
assert.NilError(t, it.Teardown())
|
||||
}()
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
t.Log("create hello service, delete, and try to create duplicate and get service already exists error")
|
||||
serviceCreate(t, it, r, "hello")
|
||||
serviceCreatePrivate(t, it, r, "hello-private")
|
||||
serviceCreateDuplicate(t, it, r, "hello-private")
|
||||
serviceCreate(r, "hello")
|
||||
serviceCreatePrivate(r, "hello-private")
|
||||
serviceCreateDuplicate(r, "hello-private")
|
||||
|
||||
t.Log("return valid info about hello service with print flags")
|
||||
serviceDescribeWithPrintFlags(t, it, r, "hello")
|
||||
serviceDescribeWithPrintFlags(r, "hello")
|
||||
|
||||
t.Log("delete hello service repeatedly and get an error")
|
||||
serviceDelete(t, it, r, "hello")
|
||||
serviceDeleteNonexistent(t, it, r, "hello")
|
||||
serviceDelete(r, "hello")
|
||||
serviceDeleteNonexistent(r, "hello")
|
||||
|
||||
t.Log("delete two services with a service nonexistent")
|
||||
serviceCreate(t, it, r, "hello")
|
||||
serviceMultipleDelete(t, it, r, "hello", "bla123")
|
||||
serviceCreate(r, "hello")
|
||||
serviceMultipleDelete(r, "hello", "bla123")
|
||||
|
||||
t.Log("create service private and make public")
|
||||
serviceCreatePrivateUpdatePublic(t, it, r, "hello-private-public")
|
||||
serviceCreatePrivateUpdatePublic(r, "hello-private-public")
|
||||
}
|
||||
|
||||
func serviceCreatePrivate(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string) {
|
||||
out := it.Kn().Run("service", "create", serviceName,
|
||||
func serviceCreatePrivate(r *test.KnRunResultCollector, serviceName string) {
|
||||
out := r.KnTest().Kn().Run("service", "create", serviceName,
|
||||
"--image", test.KnDefaultTestImage, "--cluster-local")
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "service", serviceName, "creating", "namespace", it.Kn().Namespace(), "ready"))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "service", serviceName, "creating", "namespace", r.KnTest().Kn().Namespace(), "ready"))
|
||||
|
||||
out = it.Kn().Run("service", "describe", serviceName, "--verbose")
|
||||
out = r.KnTest().Kn().Run("service", "describe", serviceName, "--verbose")
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, serving.VisibilityLabelKey, serving.VisibilityClusterLocal))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, serving.VisibilityLabelKey, serving.VisibilityClusterLocal))
|
||||
}
|
||||
|
||||
func serviceCreatePrivateUpdatePublic(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string) {
|
||||
out := it.Kn().Run("service", "create", serviceName,
|
||||
func serviceCreatePrivateUpdatePublic(r *test.KnRunResultCollector, serviceName string) {
|
||||
out := r.KnTest().Kn().Run("service", "create", serviceName,
|
||||
"--image", test.KnDefaultTestImage, "--cluster-local")
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "service", serviceName, "creating", "namespace", it.Kn().Namespace(), "ready"))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "service", serviceName, "creating", "namespace", r.KnTest().Kn().Namespace(), "ready"))
|
||||
|
||||
out = it.Kn().Run("service", "describe", serviceName, "--verbose")
|
||||
out = r.KnTest().Kn().Run("service", "describe", serviceName, "--verbose")
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, serving.VisibilityLabelKey, serving.VisibilityClusterLocal))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, serving.VisibilityLabelKey, serving.VisibilityClusterLocal))
|
||||
|
||||
out = it.Kn().Run("service", "update", serviceName,
|
||||
out = r.KnTest().Kn().Run("service", "update", serviceName,
|
||||
"--image", test.KnDefaultTestImage, "--no-cluster-local")
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "service", serviceName, "updated", "namespace", it.Kn().Namespace(), "ready"))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "service", serviceName, "updated", "namespace", r.KnTest().Kn().Namespace(), "ready"))
|
||||
|
||||
out = it.Kn().Run("service", "describe", serviceName, "--verbose")
|
||||
out = r.KnTest().Kn().Run("service", "describe", serviceName, "--verbose")
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsNone(out.Stdout, serving.VisibilityLabelKey, serving.VisibilityClusterLocal))
|
||||
assert.Check(r.T(), util.ContainsNone(out.Stdout, serving.VisibilityLabelKey, serving.VisibilityClusterLocal))
|
||||
}
|
||||
|
||||
func serviceCreateDuplicate(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string) {
|
||||
out := it.Kn().Run("service", "list", serviceName)
|
||||
func serviceCreateDuplicate(r *test.KnRunResultCollector, serviceName string) {
|
||||
out := r.KnTest().Kn().Run("service", "list", serviceName)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, strings.Contains(out.Stdout, serviceName), "The service does not exist yet")
|
||||
assert.Check(r.T(), strings.Contains(out.Stdout, serviceName), "The service does not exist yet")
|
||||
|
||||
out = it.Kn().Run("service", "create", serviceName, "--image", test.KnDefaultTestImage)
|
||||
out = r.KnTest().Kn().Run("service", "create", serviceName, "--image", test.KnDefaultTestImage)
|
||||
r.AssertError(out)
|
||||
assert.Check(t, util.ContainsAll(out.Stderr, "the service already exists"))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stderr, "the service already exists"))
|
||||
}
|
||||
|
||||
func serviceDescribeWithPrintFlags(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string) {
|
||||
out := it.Kn().Run("service", "describe", serviceName, "-o=name")
|
||||
func serviceDescribeWithPrintFlags(r *test.KnRunResultCollector, serviceName string) {
|
||||
out := r.KnTest().Kn().Run("service", "describe", serviceName, "-o=name")
|
||||
r.AssertNoError(out)
|
||||
|
||||
expectedName := fmt.Sprintf("service.serving.knative.dev/%s", serviceName)
|
||||
assert.Equal(t, strings.TrimSpace(out.Stdout), expectedName)
|
||||
assert.Equal(r.T(), strings.TrimSpace(out.Stdout), expectedName)
|
||||
}
|
||||
|
||||
func serviceDeleteNonexistent(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string) {
|
||||
out := it.Kn().Run("service", "list", serviceName)
|
||||
func serviceDeleteNonexistent(r *test.KnRunResultCollector, serviceName string) {
|
||||
out := r.KnTest().Kn().Run("service", "list", serviceName)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, !strings.Contains(out.Stdout, serviceName), "The service exists")
|
||||
assert.Check(r.T(), !strings.Contains(out.Stdout, serviceName), "The service exists")
|
||||
|
||||
out = it.Kn().Run("service", "delete", serviceName)
|
||||
out = r.KnTest().Kn().Run("service", "delete", serviceName)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, "hello", "not found"), "Failed to get 'not found' error")
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, "hello", "not found"), "Failed to get 'not found' error")
|
||||
}
|
||||
|
||||
func serviceMultipleDelete(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, existService, nonexistService string) {
|
||||
out := it.Kn().Run("service", "list")
|
||||
func serviceMultipleDelete(r *test.KnRunResultCollector, existService, nonexistService string) {
|
||||
out := r.KnTest().Kn().Run("service", "list")
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, strings.Contains(out.Stdout, existService), "The service ", existService, " does not exist (but is expected to exist)")
|
||||
assert.Check(t, !strings.Contains(out.Stdout, nonexistService), "The service", nonexistService, " exists (but is supposed to be not)")
|
||||
assert.Check(r.T(), strings.Contains(out.Stdout, existService), "The service ", existService, " does not exist (but is expected to exist)")
|
||||
assert.Check(r.T(), !strings.Contains(out.Stdout, nonexistService), "The service", nonexistService, " exists (but is supposed to be not)")
|
||||
|
||||
out = it.Kn().Run("service", "delete", existService, nonexistService)
|
||||
out = r.KnTest().Kn().Run("service", "delete", existService, nonexistService)
|
||||
r.AssertNoError(out)
|
||||
|
||||
expectedSuccess := fmt.Sprintf(`Service '%s' successfully deleted in namespace '%s'.`, existService, it.Kn().Namespace())
|
||||
expectedSuccess := fmt.Sprintf(`Service '%s' successfully deleted in namespace '%s'.`, existService, r.KnTest().Kn().Namespace())
|
||||
expectedErr := fmt.Sprintf(`services.serving.knative.dev "%s" not found`, nonexistService)
|
||||
assert.Check(t, strings.Contains(out.Stdout, expectedSuccess), "Failed to get 'successfully deleted' message")
|
||||
assert.Check(t, strings.Contains(out.Stdout, expectedErr), "Failed to get 'not found' error")
|
||||
assert.Check(r.T(), strings.Contains(out.Stdout, expectedSuccess), "Failed to get 'successfully deleted' message")
|
||||
assert.Check(r.T(), strings.Contains(out.Stdout, expectedErr), "Failed to get 'not found' error")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ func TestSinkPrefixConfig(t *testing.T) {
|
|||
assert.NilError(t, it.Teardown())
|
||||
}()
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
tc := sinkprefixTestConfig{}
|
||||
|
|
@ -73,9 +73,9 @@ func TestSinkPrefixConfig(t *testing.T) {
|
|||
defer tc.teardown()
|
||||
|
||||
t.Log("Creating a testservice")
|
||||
serviceCreate(t, it, r, "testsvc0")
|
||||
serviceCreate(r, "testsvc0")
|
||||
t.Log("create Ping sources with a sink to hello:testsvc0")
|
||||
pingSourceCreateWithConfig(t, it, r, "testpingsource0", "* * * * */1", "ping", "hello:testsvc0", tc.knConfigPath)
|
||||
pingSourceCreateWithConfig(r, "testpingsource0", "* * * * */1", "ping", "hello:testsvc0", tc.knConfigPath)
|
||||
|
||||
jpSinkRefNameInSpec := "jsonpath={.spec.sink.ref.name}"
|
||||
out, err := getResourceFieldsWithJSONPath(t, it, "pingsource", "testpingsource0", jpSinkRefNameInSpec)
|
||||
|
|
@ -83,12 +83,12 @@ func TestSinkPrefixConfig(t *testing.T) {
|
|||
assert.Equal(t, out, "testsvc0")
|
||||
|
||||
t.Log("delete Ping sources")
|
||||
pingSourceDelete(t, it, r, "testpingsource0")
|
||||
pingSourceDelete(r, "testpingsource0")
|
||||
}
|
||||
|
||||
func pingSourceCreateWithConfig(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, sourceName string, schedule string, data string, sink string, config string) {
|
||||
out := it.Kn().Run("source", "ping", "create", sourceName,
|
||||
func pingSourceCreateWithConfig(r *test.KnRunResultCollector, sourceName string, schedule string, data string, sink string, config string) {
|
||||
out := r.KnTest().Kn().Run("source", "ping", "create", sourceName,
|
||||
"--schedule", schedule, "--data", data, "--sink", sink, "--config", config)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "ping", "source", sourceName, "created", "namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "ping", "source", sourceName, "created", "namespace", r.KnTest().Kn().Namespace()))
|
||||
r.AssertNoError(out)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,37 +47,37 @@ func TestSourceApiServer(t *testing.T) {
|
|||
assert.NilError(t, err2)
|
||||
}()
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
setupForSourceAPIServer(t, it)
|
||||
serviceCreate(t, it, r, "testsvc0")
|
||||
serviceCreate(r, "testsvc0")
|
||||
|
||||
t.Log("create apiserver sources with a sink to a service")
|
||||
apiServerSourceCreate(t, it, r, "testapisource0", "Event:v1:true", "testsa", "svc:testsvc0")
|
||||
apiServerSourceCreate(t, it, r, "testapisource1", "Event:v1", "testsa", "svc:testsvc0")
|
||||
apiServerSourceCreate(r, "testapisource0", "Event:v1:true", "testsa", "svc:testsvc0")
|
||||
apiServerSourceCreate(r, "testapisource1", "Event:v1", "testsa", "svc:testsvc0")
|
||||
|
||||
t.Log("list sources")
|
||||
output := sourceList(t, it, r)
|
||||
output := sourceList(r)
|
||||
assert.Check(t, util.ContainsAll(output, "NAME", "TYPE", "RESOURCE", "SINK", "READY"))
|
||||
assert.Check(t, util.ContainsAll(output, "testapisource0", "ApiServerSource", "apiserversources.sources.knative.dev", "svc:testsvc0"))
|
||||
assert.Check(t, util.ContainsAll(output, "testapisource1", "ApiServerSource", "apiserversources.sources.knative.dev", "svc:testsvc0"))
|
||||
|
||||
t.Log("list sources in YAML format")
|
||||
output = sourceList(t, it, r, "-oyaml")
|
||||
output = sourceList(r, "-oyaml")
|
||||
assert.Check(t, util.ContainsAll(output, "testapisource1", "ApiServerSource", "Service", "testsvc0"))
|
||||
|
||||
t.Log("delete apiserver sources")
|
||||
apiServerSourceDelete(t, it, r, "testapisource0")
|
||||
apiServerSourceDelete(t, it, r, "testapisource1")
|
||||
apiServerSourceDelete(r, "testapisource0")
|
||||
apiServerSourceDelete(r, "testapisource1")
|
||||
|
||||
t.Log("create apiserver source with a missing sink service")
|
||||
apiServerSourceCreateMissingSink(t, it, r, "testapisource2", "Event:v1:true", "testsa", "svc:unknown")
|
||||
apiServerSourceCreateMissingSink(r, "testapisource2", "Event:v1:true", "testsa", "svc:unknown")
|
||||
|
||||
t.Log("update apiserver source sink service")
|
||||
apiServerSourceCreate(t, it, r, "testapisource3", "Event:v1:true", "testsa", "svc:testsvc0")
|
||||
serviceCreate(t, it, r, "testsvc1")
|
||||
apiServerSourceUpdateSink(t, it, r, "testapisource3", "svc:testsvc1")
|
||||
apiServerSourceCreate(r, "testapisource3", "Event:v1:true", "testsa", "svc:testsvc0")
|
||||
serviceCreate(r, "testsvc1")
|
||||
apiServerSourceUpdateSink(r, "testapisource3", "svc:testsvc1")
|
||||
jpSinkRefNameInSpec := "jsonpath={.spec.sink.ref.name}"
|
||||
out, err := getResourceFieldsWithJSONPath(t, it, "apiserversource.sources.knative.dev", "testapisource3", jpSinkRefNameInSpec)
|
||||
assert.NilError(t, err)
|
||||
|
|
@ -85,22 +85,22 @@ func TestSourceApiServer(t *testing.T) {
|
|||
// TODO(navidshaikh): Verify the source's status with synchronous create/update
|
||||
}
|
||||
|
||||
func apiServerSourceCreate(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, sourceName string, resources string, sa string, sink string) {
|
||||
out := it.Kn().Run("source", "apiserver", "create", sourceName, "--resource", resources, "--service-account", sa, "--sink", sink)
|
||||
func apiServerSourceCreate(r *test.KnRunResultCollector, sourceName string, resources string, sa string, sink string) {
|
||||
out := r.KnTest().Kn().Run("source", "apiserver", "create", sourceName, "--resource", resources, "--service-account", sa, "--sink", sink)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "apiserver", "source", sourceName, "created", "namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "apiserver", "source", sourceName, "created", "namespace", r.KnTest().Kn().Namespace()))
|
||||
}
|
||||
|
||||
func apiServerSourceCreateMissingSink(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, sourceName string, resources string, sa string, sink string) {
|
||||
out := it.Kn().Run("source", "apiserver", "create", sourceName, "--resource", resources, "--service-account", sa, "--sink", sink)
|
||||
func apiServerSourceCreateMissingSink(r *test.KnRunResultCollector, sourceName string, resources string, sa string, sink string) {
|
||||
out := r.KnTest().Kn().Run("source", "apiserver", "create", sourceName, "--resource", resources, "--service-account", sa, "--sink", sink)
|
||||
r.AssertError(out)
|
||||
assert.Check(t, util.ContainsAll(out.Stderr, "services.serving.knative.dev", "not found"))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stderr, "services.serving.knative.dev", "not found"))
|
||||
}
|
||||
|
||||
func apiServerSourceDelete(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, sourceName string) {
|
||||
out := it.Kn().Run("source", "apiserver", "delete", sourceName)
|
||||
func apiServerSourceDelete(r *test.KnRunResultCollector, sourceName string) {
|
||||
out := r.KnTest().Kn().Run("source", "apiserver", "delete", sourceName)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "apiserver", "source", sourceName, "deleted", "namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "apiserver", "source", sourceName, "deleted", "namespace", r.KnTest().Kn().Namespace()))
|
||||
}
|
||||
|
||||
func setupForSourceAPIServer(t *testing.T, it *test.KnTest) {
|
||||
|
|
@ -140,10 +140,10 @@ func tearDownForSourceAPIServer(t *testing.T, it *test.KnTest) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func apiServerSourceUpdateSink(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, sourceName string, sink string) {
|
||||
out := it.Kn().Run("source", "apiserver", "update", sourceName, "--sink", sink)
|
||||
func apiServerSourceUpdateSink(r *test.KnRunResultCollector, sourceName string, sink string) {
|
||||
out := r.KnTest().Kn().Run("source", "apiserver", "update", sourceName, "--sink", sink)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, sourceName, "updated", "namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, sourceName, "updated", "namespace", r.KnTest().Kn().Namespace()))
|
||||
}
|
||||
|
||||
func getResourceFieldsWithJSONPath(t *testing.T, it *test.KnTest, resource, name, jsonpath string) (string, error) {
|
||||
|
|
|
|||
|
|
@ -34,41 +34,41 @@ func TestSourceBinding(t *testing.T) {
|
|||
assert.NilError(t, it.Teardown())
|
||||
}()
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
serviceCreate(t, it, r, "testsvc0")
|
||||
serviceCreate(r, "testsvc0")
|
||||
|
||||
t.Log("create source binding")
|
||||
sourceBindingCreate(t, it, r, "my-binding0", "Deployment:apps/v1:myapp", "svc:testsvc0")
|
||||
sourceBindingCreate(r, "my-binding0", "Deployment:apps/v1:myapp", "svc:testsvc0")
|
||||
|
||||
t.Log("delete source binding")
|
||||
sourceBindingDelete(t, it, r, "my-binding0")
|
||||
sourceBindingDelete(r, "my-binding0")
|
||||
|
||||
t.Log("update source binding")
|
||||
sourceBindingCreate(t, it, r, "my-binding1", "Deployment:apps/v1:myapp", "svc:testsvc0")
|
||||
serviceCreate(t, it, r, "testsvc1")
|
||||
sourceBindingUpdate(t, it, r, "my-binding1", "Deployment:apps/v1:myapp", "svc:testsvc1")
|
||||
sourceBindingCreate(r, "my-binding1", "Deployment:apps/v1:myapp", "svc:testsvc0")
|
||||
serviceCreate(r, "testsvc1")
|
||||
sourceBindingUpdate(r, "my-binding1", "Deployment:apps/v1:myapp", "svc:testsvc1")
|
||||
jpSinkRefNameInSpec := "jsonpath={.spec.sink.ref.name}"
|
||||
out, err := getResourceFieldsWithJSONPath(t, it, "sinkbindings.sources.knative.dev", "my-binding1", jpSinkRefNameInSpec)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, out, "testsvc1")
|
||||
}
|
||||
|
||||
func sourceBindingCreate(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, bindingName string, subject string, sink string) {
|
||||
out := it.Kn().Run("source", "binding", "create", bindingName, "--subject", subject, "--sink", sink)
|
||||
func sourceBindingCreate(r *test.KnRunResultCollector, bindingName string, subject string, sink string) {
|
||||
out := r.KnTest().Kn().Run("source", "binding", "create", bindingName, "--subject", subject, "--sink", sink)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "Sink", "binding", bindingName, "created", "namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "Sink", "binding", bindingName, "created", "namespace", r.KnTest().Kn().Namespace()))
|
||||
}
|
||||
|
||||
func sourceBindingDelete(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, bindingName string) {
|
||||
out := it.Kn().Run("source", "binding", "delete", bindingName)
|
||||
func sourceBindingDelete(r *test.KnRunResultCollector, bindingName string) {
|
||||
out := r.KnTest().Kn().Run("source", "binding", "delete", bindingName)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "Sink", "binding", bindingName, "deleted", "namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "Sink", "binding", bindingName, "deleted", "namespace", r.KnTest().Kn().Namespace()))
|
||||
}
|
||||
|
||||
func sourceBindingUpdate(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, bindingName string, subject string, sink string) {
|
||||
out := it.Kn().Run("source", "binding", "update", bindingName, "--subject", subject, "--sink", sink)
|
||||
func sourceBindingUpdate(r *test.KnRunResultCollector, bindingName string, subject string, sink string) {
|
||||
out := r.KnTest().Kn().Run("source", "binding", "update", bindingName, "--subject", subject, "--sink", sink)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, bindingName, "updated", "namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stdout, bindingName, "updated", "namespace", r.KnTest().Kn().Namespace()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,16 +34,16 @@ func TestSourceListTypes(t *testing.T) {
|
|||
assert.NilError(t, it.Teardown())
|
||||
}()
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
t.Log("List available source types")
|
||||
output := sourceListTypes(t, it, r)
|
||||
output := sourceListTypes(r)
|
||||
assert.Check(t, util.ContainsAll(output, "TYPE", "NAME", "DESCRIPTION", "Ping", "ApiServer"))
|
||||
|
||||
t.Log("List available source types in YAML format")
|
||||
|
||||
output = sourceListTypes(t, it, r, "-oyaml")
|
||||
output = sourceListTypes(r, "-oyaml")
|
||||
assert.Check(t, util.ContainsAll(output, "apiextensions.k8s.io/v1beta1", "CustomResourceDefinition", "Ping", "ApiServer"))
|
||||
}
|
||||
|
||||
|
|
@ -55,27 +55,27 @@ func TestSourceList(t *testing.T) {
|
|||
assert.NilError(t, it.Teardown())
|
||||
}()
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
t.Log("List sources empty case")
|
||||
output := sourceList(t, it, r)
|
||||
output := sourceList(r)
|
||||
assert.Check(t, util.ContainsAll(output, "No", "sources", "found", "namespace"))
|
||||
assert.Check(t, util.ContainsNone(output, "NAME", "TYPE", "RESOURCE", "SINK", "READY"))
|
||||
|
||||
// non empty list case is tested in test/e2e/source_apiserver_it.go where source setup is present
|
||||
}
|
||||
|
||||
func sourceListTypes(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, args ...string) string {
|
||||
func sourceListTypes(r *test.KnRunResultCollector, args ...string) string {
|
||||
cmd := append([]string{"source", "list-types"}, args...)
|
||||
out := it.Kn().Run(cmd...)
|
||||
out := r.KnTest().Kn().Run(cmd...)
|
||||
r.AssertNoError(out)
|
||||
return out.Stdout
|
||||
}
|
||||
|
||||
func sourceList(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, args ...string) string {
|
||||
func sourceList(r *test.KnRunResultCollector, args ...string) string {
|
||||
cmd := append([]string{"source", "list"}, args...)
|
||||
out := it.Kn().Run(cmd...)
|
||||
out := r.KnTest().Kn().Run(cmd...)
|
||||
r.AssertNoError(out)
|
||||
return out.Stdout
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func TestTektonPipeline(t *testing.T) {
|
|||
err = waitForPipelineSuccess(kubectl)
|
||||
assert.NilError(t, err)
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
|
||||
const serviceName = "hello"
|
||||
out := it.Kn().Run("service", "describe", serviceName)
|
||||
|
|
|
|||
|
|
@ -88,314 +88,314 @@ func TestTrafficSplit(t *testing.T) {
|
|||
t.Run("50:50",
|
||||
func(t *testing.T) {
|
||||
t.Log("tag two revisions as v1 and v2 and give 50-50% share")
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
serviceName := test.GetNextServiceName(serviceBase)
|
||||
serviceCreate(t, it, r, serviceName)
|
||||
serviceCreate(r, serviceName)
|
||||
|
||||
rev1 := fmt.Sprintf("%s-rev-1", serviceName)
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--env", "TARGET=v1", "--revision-name", rev1)
|
||||
serviceUpdateWithOptions(r, serviceName, "--env", "TARGET=v1", "--revision-name", rev1)
|
||||
|
||||
rev2 := fmt.Sprintf("%s-rev-2", serviceName)
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
serviceUpdateWithOptions(r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
|
||||
tflags := []string{"--tag", fmt.Sprintf("%s=v1,%s=v2", rev1, rev2),
|
||||
"--traffic", "v1=50,v2=50"}
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, tflags...)
|
||||
serviceUpdateWithOptions(r, serviceName, tflags...)
|
||||
|
||||
// make ordered fields per tflags (tag, revision, percent, latest)
|
||||
expectedTargets := []TargetFields{newTargetFields("v1", rev1, 50, false), newTargetFields("v2", rev2, 50, false)}
|
||||
verifyTargets(t, it, r, serviceName, expectedTargets)
|
||||
serviceDelete(t, it, r, serviceName)
|
||||
verifyTargets(r, serviceName, expectedTargets)
|
||||
serviceDelete(r, serviceName)
|
||||
},
|
||||
)
|
||||
t.Run("20:80",
|
||||
func(t *testing.T) {
|
||||
t.Log("ramp/up down a revision to 20% adjusting other traffic to accommodate")
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
serviceName := test.GetNextServiceName(serviceBase)
|
||||
serviceCreate(t, it, r, serviceName)
|
||||
serviceCreate(r, serviceName)
|
||||
|
||||
rev1 := fmt.Sprintf("%s-rev-1", serviceName)
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--env", "TARGET=v1", "--revision-name", rev1)
|
||||
serviceUpdateWithOptions(r, serviceName, "--env", "TARGET=v1", "--revision-name", rev1)
|
||||
|
||||
rev2 := fmt.Sprintf("%s-rev-2", serviceName)
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
serviceUpdateWithOptions(r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--traffic", fmt.Sprintf("%s=20,%s=80", rev1, rev2))
|
||||
serviceUpdateWithOptions(r, serviceName, "--traffic", fmt.Sprintf("%s=20,%s=80", rev1, rev2))
|
||||
|
||||
expectedTargets := []TargetFields{newTargetFields("", rev1, 20, false), newTargetFields("", rev2, 80, false)}
|
||||
verifyTargets(t, it, r, serviceName, expectedTargets)
|
||||
serviceDelete(t, it, r, serviceName)
|
||||
verifyTargets(r, serviceName, expectedTargets)
|
||||
serviceDelete(r, serviceName)
|
||||
},
|
||||
)
|
||||
t.Run("TagCandidate",
|
||||
func(t *testing.T) {
|
||||
t.Log("tag a revision as candidate, without otherwise changing any traffic split")
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
serviceName := test.GetNextServiceName(serviceBase)
|
||||
rev1 := fmt.Sprintf("%s-rev-1", serviceName)
|
||||
serviceCreateWithOptions(t, it, r, serviceName, "--revision-name", rev1)
|
||||
serviceCreateWithOptions(r, serviceName, "--revision-name", rev1)
|
||||
|
||||
rev2 := fmt.Sprintf("%s-rev-2", serviceName)
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--env", "TARGET=v1", "--revision-name", rev2)
|
||||
serviceUpdateWithOptions(r, serviceName, "--env", "TARGET=v1", "--revision-name", rev2)
|
||||
|
||||
// no traffic, append new target with tag in traffic block
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--tag", fmt.Sprintf("%s=%s", rev1, "candidate"))
|
||||
serviceUpdateWithOptions(r, serviceName, "--tag", fmt.Sprintf("%s=%s", rev1, "candidate"))
|
||||
|
||||
expectedTargets := []TargetFields{newTargetFields("", rev2, 100, true), newTargetFields("candidate", rev1, 0, false)}
|
||||
verifyTargets(t, it, r, serviceName, expectedTargets)
|
||||
serviceDelete(t, it, r, serviceName)
|
||||
verifyTargets(r, serviceName, expectedTargets)
|
||||
serviceDelete(r, serviceName)
|
||||
},
|
||||
)
|
||||
t.Run("TagCandidate:2:98",
|
||||
func(t *testing.T) {
|
||||
t.Log("tag a revision as candidate, set 2% traffic adjusting other traffic to accommodate")
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
serviceName := test.GetNextServiceName(serviceBase)
|
||||
rev1 := fmt.Sprintf("%s-rev-1", serviceName)
|
||||
serviceCreateWithOptions(t, it, r, serviceName, "--revision-name", rev1)
|
||||
serviceCreateWithOptions(r, serviceName, "--revision-name", rev1)
|
||||
|
||||
rev2 := fmt.Sprintf("%s-rev-2", serviceName)
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--env", "TARGET=v1", "--revision-name", rev2)
|
||||
serviceUpdateWithOptions(r, serviceName, "--env", "TARGET=v1", "--revision-name", rev2)
|
||||
|
||||
// traffic by tag name and use % at the end
|
||||
serviceUpdateWithOptions(t, it, r, serviceName,
|
||||
serviceUpdateWithOptions(r, serviceName,
|
||||
"--tag", fmt.Sprintf("%s=%s", rev1, "candidate"),
|
||||
"--traffic", "candidate=2%,@latest=98%")
|
||||
|
||||
expectedTargets := []TargetFields{newTargetFields("", rev2, 98, true), newTargetFields("candidate", rev1, 2, false)}
|
||||
verifyTargets(t, it, r, serviceName, expectedTargets)
|
||||
serviceDelete(t, it, r, serviceName)
|
||||
verifyTargets(r, serviceName, expectedTargets)
|
||||
serviceDelete(r, serviceName)
|
||||
},
|
||||
)
|
||||
t.Run("TagCurrent",
|
||||
func(t *testing.T) {
|
||||
t.Log("update tag for a revision from candidate to current, tag current is present on another revision")
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
serviceName := test.GetNextServiceName(serviceBase)
|
||||
// make available 3 revisions for service first
|
||||
rev1 := fmt.Sprintf("%s-rev-1", serviceName)
|
||||
serviceCreateWithOptions(t, it, r, serviceName, "--revision-name", rev1)
|
||||
serviceCreateWithOptions(r, serviceName, "--revision-name", rev1)
|
||||
|
||||
rev2 := fmt.Sprintf("%s-rev-2", serviceName)
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
serviceUpdateWithOptions(r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
|
||||
rev3 := fmt.Sprintf("%s-rev-3", serviceName)
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--env", "TARGET=v3", "--revision-name", rev3) //note that this gives 100% traffic to latest revision (rev3)
|
||||
serviceUpdateWithOptions(r, serviceName, "--env", "TARGET=v3", "--revision-name", rev3) //note that this gives 100% traffic to latest revision (rev3)
|
||||
|
||||
// make existing state: tag current and candidate exist in traffic block
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--tag", fmt.Sprintf("%s=current,%s=candidate", rev1, rev2))
|
||||
serviceUpdateWithOptions(r, serviceName, "--tag", fmt.Sprintf("%s=current,%s=candidate", rev1, rev2))
|
||||
|
||||
// desired state of tags: update tag of revision (rev2) from candidate to current (which is present on rev1)
|
||||
//untag first to update
|
||||
serviceUpdateWithOptions(t, it, r, serviceName,
|
||||
serviceUpdateWithOptions(r, serviceName,
|
||||
"--untag", "current,candidate",
|
||||
"--tag", fmt.Sprintf("%s=current", rev2))
|
||||
|
||||
// there will be 2 targets in existing block 1. @latest, 2.for revision $rev2
|
||||
// target for rev1 is removed as it had no traffic and we untagged it's tag current
|
||||
expectedTargets := []TargetFields{newTargetFields("", rev3, 100, true), newTargetFields("current", rev2, 0, false)}
|
||||
verifyTargets(t, it, r, serviceName, expectedTargets)
|
||||
serviceDelete(t, it, r, serviceName)
|
||||
verifyTargets(r, serviceName, expectedTargets)
|
||||
serviceDelete(r, serviceName)
|
||||
},
|
||||
)
|
||||
t.Run("TagStagingLatest",
|
||||
func(t *testing.T) {
|
||||
t.Log("update tag from testing to staging for @latest revision")
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
serviceName := test.GetNextServiceName(serviceBase)
|
||||
rev1 := fmt.Sprintf("%s-rev-1", serviceName)
|
||||
serviceCreateWithOptions(t, it, r, serviceName, "--revision-name", rev1)
|
||||
serviceCreateWithOptions(r, serviceName, "--revision-name", rev1)
|
||||
|
||||
// make existing state: tag @latest as testing
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--tag", "@latest=testing")
|
||||
serviceUpdateWithOptions(r, serviceName, "--tag", "@latest=testing")
|
||||
|
||||
// desired state: change tag from testing to staging
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--untag", "testing", "--tag", "@latest=staging")
|
||||
serviceUpdateWithOptions(r, serviceName, "--untag", "testing", "--tag", "@latest=staging")
|
||||
|
||||
expectedTargets := []TargetFields{newTargetFields("staging", rev1, 100, true)}
|
||||
verifyTargets(t, it, r, serviceName, expectedTargets)
|
||||
serviceDelete(t, it, r, serviceName)
|
||||
verifyTargets(r, serviceName, expectedTargets)
|
||||
serviceDelete(r, serviceName)
|
||||
},
|
||||
)
|
||||
t.Run("TagStagingNonLatest",
|
||||
func(t *testing.T) {
|
||||
t.Log("update tag from testing to staging for a revision (non @latest)")
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
serviceName := test.GetNextServiceName(serviceBase)
|
||||
rev1 := fmt.Sprintf("%s-rev-1", serviceName)
|
||||
serviceCreateWithOptions(t, it, r, serviceName, "--revision-name", rev1)
|
||||
serviceCreateWithOptions(r, serviceName, "--revision-name", rev1)
|
||||
|
||||
rev2 := fmt.Sprintf("%s-rev-2", serviceName)
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
serviceUpdateWithOptions(r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
|
||||
// make existing state: tag a revision as testing
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--tag", fmt.Sprintf("%s=testing", rev1))
|
||||
serviceUpdateWithOptions(r, serviceName, "--tag", fmt.Sprintf("%s=testing", rev1))
|
||||
|
||||
// desired state: change tag from testing to staging
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--untag", "testing", "--tag", fmt.Sprintf("%s=staging", rev1))
|
||||
serviceUpdateWithOptions(r, serviceName, "--untag", "testing", "--tag", fmt.Sprintf("%s=staging", rev1))
|
||||
|
||||
expectedTargets := []TargetFields{newTargetFields("", rev2, 100, true),
|
||||
newTargetFields("staging", rev1, 0, false)}
|
||||
verifyTargets(t, it, r, serviceName, expectedTargets)
|
||||
serviceDelete(t, it, r, serviceName)
|
||||
verifyTargets(r, serviceName, expectedTargets)
|
||||
serviceDelete(r, serviceName)
|
||||
},
|
||||
)
|
||||
// test reducing number of targets from traffic blockdd
|
||||
t.Run("RemoveTag",
|
||||
func(t *testing.T) {
|
||||
t.Log("remove a revision with tag old from traffic block entirely")
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
serviceName := test.GetNextServiceName(serviceBase)
|
||||
rev1 := fmt.Sprintf("%s-rev-1", serviceName)
|
||||
serviceCreateWithOptions(t, it, r, serviceName, "--revision-name", rev1)
|
||||
serviceCreateWithOptions(r, serviceName, "--revision-name", rev1)
|
||||
|
||||
rev2 := fmt.Sprintf("%s-rev-2", serviceName)
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
serviceUpdateWithOptions(r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
|
||||
// existing state: traffic block having a revision with tag old and some traffic
|
||||
serviceUpdateWithOptions(t, it, r, serviceName,
|
||||
serviceUpdateWithOptions(r, serviceName,
|
||||
"--tag", fmt.Sprintf("%s=old", rev1),
|
||||
"--traffic", "old=2,@latest=98")
|
||||
|
||||
// desired state: remove revision with tag old
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--untag", "old", "--traffic", "@latest=100")
|
||||
serviceUpdateWithOptions(r, serviceName, "--untag", "old", "--traffic", "@latest=100")
|
||||
|
||||
expectedTargets := []TargetFields{newTargetFields("", rev2, 100, true)}
|
||||
verifyTargets(t, it, r, serviceName, expectedTargets)
|
||||
serviceDelete(t, it, r, serviceName)
|
||||
verifyTargets(r, serviceName, expectedTargets)
|
||||
serviceDelete(r, serviceName)
|
||||
},
|
||||
)
|
||||
t.Run("TagStable:50:50",
|
||||
func(t *testing.T) {
|
||||
t.Log("tag a revision as stable and current with 50-50% traffic")
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
serviceName := test.GetNextServiceName(serviceBase)
|
||||
rev1 := fmt.Sprintf("%s-rev-1", serviceName)
|
||||
serviceCreateWithOptions(t, it, r, serviceName, "--revision-name", rev1)
|
||||
serviceCreateWithOptions(r, serviceName, "--revision-name", rev1)
|
||||
|
||||
// existing state: traffic block having two targets
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--env", "TARGET=v2")
|
||||
serviceUpdateWithOptions(r, serviceName, "--env", "TARGET=v2")
|
||||
|
||||
// desired state: tag non-@latest revision with two tags and 50-50% traffic each
|
||||
serviceUpdateWithOptions(t, it, r, serviceName,
|
||||
serviceUpdateWithOptions(r, serviceName,
|
||||
"--tag", fmt.Sprintf("%s=stable,%s=current", rev1, rev1),
|
||||
"--traffic", "stable=50%,current=50%")
|
||||
|
||||
expectedTargets := []TargetFields{newTargetFields("stable", rev1, 50, false), newTargetFields("current", rev1, 50, false)}
|
||||
verifyTargets(t, it, r, serviceName, expectedTargets)
|
||||
serviceDelete(t, it, r, serviceName)
|
||||
verifyTargets(r, serviceName, expectedTargets)
|
||||
serviceDelete(r, serviceName)
|
||||
},
|
||||
)
|
||||
t.Run("RevertToLatest",
|
||||
func(t *testing.T) {
|
||||
t.Log("revert all traffic to latest ready revision of service")
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
serviceName := test.GetNextServiceName(serviceBase)
|
||||
rev1 := fmt.Sprintf("%s-rev-1", serviceName)
|
||||
serviceCreateWithOptions(t, it, r, serviceName, "--revision-name", rev1)
|
||||
serviceCreateWithOptions(r, serviceName, "--revision-name", rev1)
|
||||
|
||||
rev2 := fmt.Sprintf("%s-rev-2", serviceName)
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
serviceUpdateWithOptions(r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
|
||||
// existing state: latest ready revision not getting any traffic
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--traffic", fmt.Sprintf("%s=100", rev1))
|
||||
serviceUpdateWithOptions(r, serviceName, "--traffic", fmt.Sprintf("%s=100", rev1))
|
||||
|
||||
// desired state: revert traffic to latest ready revision
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--traffic", "@latest=100")
|
||||
serviceUpdateWithOptions(r, serviceName, "--traffic", "@latest=100")
|
||||
|
||||
expectedTargets := []TargetFields{newTargetFields("", rev2, 100, true)}
|
||||
verifyTargets(t, it, r, serviceName, expectedTargets)
|
||||
serviceDelete(t, it, r, serviceName)
|
||||
verifyTargets(r, serviceName, expectedTargets)
|
||||
serviceDelete(r, serviceName)
|
||||
},
|
||||
)
|
||||
t.Run("TagLatestAsCurrent",
|
||||
func(t *testing.T) {
|
||||
t.Log("tag latest ready revision of service as current")
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
serviceName := test.GetNextServiceName(serviceBase)
|
||||
// existing state: latest revision has no tag
|
||||
rev1 := fmt.Sprintf("%s-rev-1", serviceName)
|
||||
serviceCreateWithOptions(t, it, r, serviceName, "--revision-name", rev1)
|
||||
serviceCreateWithOptions(r, serviceName, "--revision-name", rev1)
|
||||
|
||||
// desired state: tag latest ready revision as 'current'
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--tag", "@latest=current")
|
||||
serviceUpdateWithOptions(r, serviceName, "--tag", "@latest=current")
|
||||
|
||||
expectedTargets := []TargetFields{newTargetFields("current", rev1, 100, true)}
|
||||
verifyTargets(t, it, r, serviceName, expectedTargets)
|
||||
serviceDelete(t, it, r, serviceName)
|
||||
verifyTargets(r, serviceName, expectedTargets)
|
||||
serviceDelete(r, serviceName)
|
||||
},
|
||||
)
|
||||
t.Run("UpdateTag:100:0",
|
||||
func(t *testing.T) {
|
||||
t.Log("update tag for a revision as testing and assign all the traffic to it")
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
serviceName := test.GetNextServiceName(serviceBase)
|
||||
rev1 := fmt.Sprintf("%s-rev-1", serviceName)
|
||||
serviceCreateWithOptions(t, it, r, serviceName, "--revision-name", rev1)
|
||||
serviceCreateWithOptions(r, serviceName, "--revision-name", rev1)
|
||||
|
||||
rev2 := fmt.Sprintf("%s-rev-2", serviceName)
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
serviceUpdateWithOptions(r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
|
||||
// existing state: two revision exists with traffic share and
|
||||
// each revision has tag and traffic portions
|
||||
serviceUpdateWithOptions(t, it, r, serviceName,
|
||||
serviceUpdateWithOptions(r, serviceName,
|
||||
"--tag", fmt.Sprintf("@latest=current,%s=candidate", rev1),
|
||||
"--traffic", "current=90,candidate=10")
|
||||
|
||||
// desired state: update tag for rev1 as testing (from candidate) with 100% traffic
|
||||
serviceUpdateWithOptions(t, it, r, serviceName,
|
||||
serviceUpdateWithOptions(r, serviceName,
|
||||
"--untag", "candidate", "--tag", fmt.Sprintf("%s=testing", rev1),
|
||||
"--traffic", "testing=100")
|
||||
|
||||
expectedTargets := []TargetFields{newTargetFields("current", rev2, 0, true),
|
||||
newTargetFields("testing", rev1, 100, false)}
|
||||
verifyTargets(t, it, r, serviceName, expectedTargets)
|
||||
serviceDelete(t, it, r, serviceName)
|
||||
verifyTargets(r, serviceName, expectedTargets)
|
||||
serviceDelete(r, serviceName)
|
||||
},
|
||||
)
|
||||
t.Run("TagReplace",
|
||||
func(t *testing.T) {
|
||||
t.Log("replace latest tag of a revision with old and give latest to another revision")
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
serviceName := test.GetNextServiceName(serviceBase)
|
||||
rev1 := fmt.Sprintf("%s-rev-1", serviceName)
|
||||
serviceCreateWithOptions(t, it, r, serviceName, "--revision-name", rev1)
|
||||
serviceCreateWithOptions(r, serviceName, "--revision-name", rev1)
|
||||
|
||||
rev2 := fmt.Sprintf("%s-rev-2", serviceName)
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
serviceUpdateWithOptions(r, serviceName, "--env", "TARGET=v2", "--revision-name", rev2)
|
||||
|
||||
// existing state: a revision exist with latest tag
|
||||
serviceUpdateWithOptions(t, it, r, serviceName, "--tag", fmt.Sprintf("%s=latest", rev1))
|
||||
serviceUpdateWithOptions(r, serviceName, "--tag", fmt.Sprintf("%s=latest", rev1))
|
||||
|
||||
// desired state of revision tags: rev1=old rev2=latest
|
||||
serviceUpdateWithOptions(t, it, r, serviceName,
|
||||
serviceUpdateWithOptions(r, serviceName,
|
||||
"--untag", "latest",
|
||||
"--tag", fmt.Sprintf("%s=old,%s=latest", rev1, rev2))
|
||||
|
||||
|
|
@ -406,34 +406,34 @@ func TestTrafficSplit(t *testing.T) {
|
|||
// In spec of traffic block (not status) either latestReadyRevision:true or revisionName can be given per target
|
||||
newTargetFields("latest", rev2, 0, false)}
|
||||
|
||||
verifyTargets(t, it, r, serviceName, expectedTargets)
|
||||
serviceDelete(t, it, r, serviceName)
|
||||
verifyTargets(r, serviceName, expectedTargets)
|
||||
serviceDelete(r, serviceName)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func verifyTargets(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string, expectedTargets []TargetFields) {
|
||||
out := serviceDescribeWithJSONPath(t, it, r, serviceName, targetsJsonPath)
|
||||
assert.Check(t, out != "")
|
||||
func verifyTargets(r *test.KnRunResultCollector, serviceName string, expectedTargets []TargetFields) {
|
||||
out := serviceDescribeWithJSONPath(r, serviceName, targetsJsonPath)
|
||||
assert.Check(r.T(), out != "")
|
||||
actualTargets, err := splitTargets(out, targetsSeparator, len(expectedTargets))
|
||||
assert.NilError(t, err)
|
||||
formattedActualTargets := formatActualTargets(t, it, actualTargets)
|
||||
assert.DeepEqual(t, expectedTargets, formattedActualTargets)
|
||||
if t.Failed() {
|
||||
r.AddDump("service", serviceName, it.Kn().Namespace())
|
||||
assert.NilError(r.T(), err)
|
||||
formattedActualTargets := formatActualTargets(r.T(), r.KnTest(), actualTargets)
|
||||
assert.DeepEqual(r.T(), expectedTargets, formattedActualTargets)
|
||||
if r.T().Failed() {
|
||||
r.AddDump("service", serviceName, r.KnTest().Kn().Namespace())
|
||||
}
|
||||
}
|
||||
|
||||
func serviceDescribeWithJSONPath(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName, jsonpath string) string {
|
||||
out := it.Kn().Run("service", "describe", serviceName, "-o", jsonpath)
|
||||
func serviceDescribeWithJSONPath(r *test.KnRunResultCollector, serviceName, jsonpath string) string {
|
||||
out := r.KnTest().Kn().Run("service", "describe", serviceName, "-o", jsonpath)
|
||||
r.AssertNoError(out)
|
||||
return out.Stdout
|
||||
}
|
||||
|
||||
func serviceUpdateWithOptions(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceName string, options ...string) {
|
||||
func serviceUpdateWithOptions(r *test.KnRunResultCollector, serviceName string, options ...string) {
|
||||
command := []string{"service", "update", serviceName}
|
||||
command = append(command, options...)
|
||||
out := it.Kn().Run(command...)
|
||||
out := r.KnTest().Kn().Run(command...)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "Service", serviceName, "updating", "namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "Service", serviceName, "updating", "namespace", r.KnTest().Kn().Namespace()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,20 +34,20 @@ func TestInjectBrokerTrigger(t *testing.T) {
|
|||
assert.NilError(t, it.Teardown())
|
||||
}()
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
assert.NilError(t, err)
|
||||
|
||||
serviceCreate(t, it, r, "sinksvc0")
|
||||
serviceCreate(t, it, r, "sinksvc1")
|
||||
serviceCreate(r, "sinksvc0")
|
||||
serviceCreate(r, "sinksvc1")
|
||||
|
||||
t.Log("create triggers and list them")
|
||||
triggerCreateWithInject(t, it, r, "trigger1", "sinksvc0", []string{"a=b"})
|
||||
triggerCreateWithInject(t, it, r, "trigger2", "sinksvc1", []string{"type=knative.dev.bar", "source=ping"})
|
||||
verifyTriggerList(t, it, r, "trigger1", "trigger2")
|
||||
triggerDelete(t, it, r, "trigger1")
|
||||
triggerDelete(t, it, r, "trigger2")
|
||||
triggerCreateWithInject(r, "trigger1", "sinksvc0", []string{"a=b"})
|
||||
triggerCreateWithInject(r, "trigger2", "sinksvc1", []string{"type=knative.dev.bar", "source=ping"})
|
||||
verifyTriggerList(r, "trigger1", "trigger2")
|
||||
triggerDelete(r, "trigger1")
|
||||
triggerDelete(r, "trigger2")
|
||||
|
||||
t.Log("create trigger with error")
|
||||
out := it.Kn().Run("trigger", "create", "errorTrigger", "--broker", "mybroker", "--inject-broker",
|
||||
|
|
@ -56,12 +56,12 @@ func TestInjectBrokerTrigger(t *testing.T) {
|
|||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stderr, "broker", "name", "'default'", "--inject-broker", "flag"))
|
||||
}
|
||||
|
||||
func triggerCreateWithInject(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, name string, sinksvc string, filters []string) {
|
||||
func triggerCreateWithInject(r *test.KnRunResultCollector, name string, sinksvc string, filters []string) {
|
||||
args := []string{"trigger", "create", name, "--broker", "default", "--inject-broker", "--sink", "svc:" + sinksvc}
|
||||
for _, v := range filters {
|
||||
args = append(args, "--filter", v)
|
||||
}
|
||||
out := it.Kn().Run(args...)
|
||||
out := r.KnTest().Kn().Run(args...)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "Trigger", name, "created", "namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "Trigger", name, "created", "namespace", r.KnTest().Kn().Namespace()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,46 +37,46 @@ func TestBrokerTrigger(t *testing.T) {
|
|||
assert.NilError(t, it.Teardown())
|
||||
}()
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
err = lableNamespaceForDefaultBroker(t, it)
|
||||
assert.NilError(t, err)
|
||||
defer unlableNamespaceForDefaultBroker(t, it)
|
||||
|
||||
serviceCreate(t, it, r, "sinksvc0")
|
||||
serviceCreate(t, it, r, "sinksvc1")
|
||||
serviceCreate(r, "sinksvc0")
|
||||
serviceCreate(r, "sinksvc1")
|
||||
|
||||
t.Log("create triggers and list them")
|
||||
triggerCreate(t, it, r, "trigger1", "sinksvc0", []string{"a=b"})
|
||||
triggerCreate(t, it, r, "trigger2", "sinksvc1", []string{"type=knative.dev.bar", "source=ping"})
|
||||
verifyTriggerList(t, it, r, "trigger1", "trigger2")
|
||||
triggerDelete(t, it, r, "trigger1")
|
||||
triggerDelete(t, it, r, "trigger2")
|
||||
triggerCreate(r, "trigger1", "sinksvc0", []string{"a=b"})
|
||||
triggerCreate(r, "trigger2", "sinksvc1", []string{"type=knative.dev.bar", "source=ping"})
|
||||
verifyTriggerList(r, "trigger1", "trigger2")
|
||||
triggerDelete(r, "trigger1")
|
||||
triggerDelete(r, "trigger2")
|
||||
|
||||
t.Log("create a trigger and delete it")
|
||||
triggerCreate(t, it, r, "deltrigger", "sinksvc0", []string{"a=b"})
|
||||
triggerDelete(t, it, r, "deltrigger")
|
||||
verifyTriggerNotfound(t, it, r, "deltrigger")
|
||||
triggerCreate(r, "deltrigger", "sinksvc0", []string{"a=b"})
|
||||
triggerDelete(r, "deltrigger")
|
||||
verifyTriggerNotfound(r, "deltrigger")
|
||||
|
||||
t.Log("create a trigger with filters and remove them one by one")
|
||||
triggerCreate(t, it, r, "filtertrigger", "sinksvc0", []string{"foo=bar", "source=ping"})
|
||||
verifyTriggerDescribe(t, it, r, "filtertrigger", "default", "sinksvc0", []string{"foo", "bar", "source", "ping"})
|
||||
triggerUpdate(t, it, r, "filtertrigger", "foo-", "sinksvc0")
|
||||
verifyTriggerDescribe(t, it, r, "filtertrigger", "default", "sinksvc0", []string{"source", "ping"})
|
||||
triggerUpdate(t, it, r, "filtertrigger", "source-", "sinksvc0")
|
||||
verifyTriggerDescribe(t, it, r, "filtertrigger", "default", "sinksvc0", nil)
|
||||
triggerDelete(t, it, r, "filtertrigger")
|
||||
triggerCreate(r, "filtertrigger", "sinksvc0", []string{"foo=bar", "source=ping"})
|
||||
verifyTriggerDescribe(r, "filtertrigger", "default", "sinksvc0", []string{"foo", "bar", "source", "ping"})
|
||||
triggerUpdate(r, "filtertrigger", "foo-", "sinksvc0")
|
||||
verifyTriggerDescribe(r, "filtertrigger", "default", "sinksvc0", []string{"source", "ping"})
|
||||
triggerUpdate(r, "filtertrigger", "source-", "sinksvc0")
|
||||
verifyTriggerDescribe(r, "filtertrigger", "default", "sinksvc0", nil)
|
||||
triggerDelete(r, "filtertrigger")
|
||||
|
||||
t.Log("create a trigger, describe and update it")
|
||||
triggerCreate(t, it, r, "updtrigger", "sinksvc0", []string{"a=b"})
|
||||
verifyTriggerDescribe(t, it, r, "updtrigger", "default", "sinksvc0", []string{"a", "b"})
|
||||
triggerUpdate(t, it, r, "updtrigger", "type=knative.dev.bar", "sinksvc1")
|
||||
verifyTriggerDescribe(t, it, r, "updtrigger", "default", "sinksvc1", []string{"a", "b", "type", "knative.dev.bar"})
|
||||
triggerDelete(t, it, r, "updtrigger")
|
||||
triggerCreate(r, "updtrigger", "sinksvc0", []string{"a=b"})
|
||||
verifyTriggerDescribe(r, "updtrigger", "default", "sinksvc0", []string{"a", "b"})
|
||||
triggerUpdate(r, "updtrigger", "type=knative.dev.bar", "sinksvc1")
|
||||
verifyTriggerDescribe(r, "updtrigger", "default", "sinksvc1", []string{"a", "b", "type", "knative.dev.bar"})
|
||||
triggerDelete(r, "updtrigger")
|
||||
|
||||
t.Log("create trigger with error return")
|
||||
triggerCreateMissingSink(t, it, r, "errtrigger", "notfound")
|
||||
triggerCreateMissingSink(r, "errtrigger", "notfound")
|
||||
}
|
||||
|
||||
// Private functions
|
||||
|
|
@ -105,55 +105,55 @@ func lableNamespaceForDefaultBroker(t *testing.T, it *test.KnTest) error {
|
|||
})
|
||||
}
|
||||
|
||||
func triggerCreate(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, name string, sinksvc string, filters []string) {
|
||||
func triggerCreate(r *test.KnRunResultCollector, name string, sinksvc string, filters []string) {
|
||||
args := []string{"trigger", "create", name, "--broker", "default", "--sink", "svc:" + sinksvc}
|
||||
if len(filters) > 0 {
|
||||
for _, v := range filters {
|
||||
args = append(args, "--filter", v)
|
||||
}
|
||||
}
|
||||
out := it.Kn().Run(args...)
|
||||
out := r.KnTest().Kn().Run(args...)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "Trigger", name, "created", "namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "Trigger", name, "created", "namespace", r.KnTest().Kn().Namespace()))
|
||||
}
|
||||
|
||||
func triggerCreateMissingSink(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, name string, sinksvc string) {
|
||||
out := it.Kn().Run("trigger", "create", name, "--broker", "default", "--sink", "svc:"+sinksvc)
|
||||
func triggerCreateMissingSink(r *test.KnRunResultCollector, name string, sinksvc string) {
|
||||
out := r.KnTest().Kn().Run("trigger", "create", name, "--broker", "default", "--sink", "svc:"+sinksvc)
|
||||
r.AssertError(out)
|
||||
assert.Check(t, util.ContainsAll(out.Stderr, "services.serving.knative.dev", "not found"))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stderr, "services.serving.knative.dev", "not found"))
|
||||
}
|
||||
|
||||
func triggerDelete(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, name string) {
|
||||
out := it.Kn().Run("trigger", "delete", name)
|
||||
func triggerDelete(r *test.KnRunResultCollector, name string) {
|
||||
out := r.KnTest().Kn().Run("trigger", "delete", name)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "Trigger", name, "deleted", "namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "Trigger", name, "deleted", "namespace", r.KnTest().Kn().Namespace()))
|
||||
}
|
||||
|
||||
func triggerUpdate(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, name string, filter string, sinksvc string) {
|
||||
out := it.Kn().Run("trigger", "update", name, "--filter", filter, "--sink", "svc:"+sinksvc)
|
||||
func triggerUpdate(r *test.KnRunResultCollector, name string, filter string, sinksvc string) {
|
||||
out := r.KnTest().Kn().Run("trigger", "update", name, "--filter", filter, "--sink", "svc:"+sinksvc)
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "Trigger", name, "updated", "namespace", it.Kn().Namespace()))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "Trigger", name, "updated", "namespace", r.KnTest().Kn().Namespace()))
|
||||
}
|
||||
|
||||
func verifyTriggerList(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, triggers ...string) {
|
||||
out := it.Kn().Run("trigger", "list")
|
||||
func verifyTriggerList(r *test.KnRunResultCollector, triggers ...string) {
|
||||
out := r.KnTest().Kn().Run("trigger", "list")
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, triggers...))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, triggers...))
|
||||
}
|
||||
|
||||
func verifyTriggerDescribe(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, name string, broker string, sink string, filters []string) {
|
||||
out := it.Kn().Run("trigger", "describe", name)
|
||||
func verifyTriggerDescribe(r *test.KnRunResultCollector, name string, broker string, sink string, filters []string) {
|
||||
out := r.KnTest().Kn().Run("trigger", "describe", name)
|
||||
r.AssertNoError(out)
|
||||
if len(filters) > 0 {
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, filters...))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, filters...))
|
||||
} else {
|
||||
assert.Check(t, util.ContainsNone(out.Stdout, "Filter"))
|
||||
assert.Check(r.T(), util.ContainsNone(out.Stdout, "Filter"))
|
||||
}
|
||||
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, name, broker, sink))
|
||||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, name, broker, sink))
|
||||
}
|
||||
|
||||
func verifyTriggerNotfound(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, name string) {
|
||||
out := it.Kn().Run("trigger", "describe", name)
|
||||
func verifyTriggerNotfound(r *test.KnRunResultCollector, name string) {
|
||||
out := r.KnTest().Kn().Run("trigger", "describe", name)
|
||||
r.AssertError(out)
|
||||
assert.Check(t, util.ContainsAll(out.Stderr, name, "not found"))
|
||||
assert.Check(r.T(), util.ContainsAll(out.Stderr, name, "not found"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,10 +28,16 @@ import (
|
|||
func TestVersion(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := test.NewKnRunResultCollector(t)
|
||||
it, err := test.NewKnTest()
|
||||
assert.NilError(t, err)
|
||||
defer func() {
|
||||
assert.NilError(t, it.Teardown())
|
||||
}()
|
||||
|
||||
r := test.NewKnRunResultCollector(t, it)
|
||||
defer r.DumpIfFailed()
|
||||
|
||||
out := test.Kn{}.Run("version")
|
||||
out := r.KnTest().Kn().RunNoNamespace("version")
|
||||
r.AssertNoError(out)
|
||||
assert.Check(t, util.ContainsAll(out.Stdout, "Version"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue