Skip to content

Commit

Permalink
Addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasgun committed Jul 22, 2021
1 parent 1c68afb commit 1394f66
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/kn/commands/source/ping/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func NewPingCreateCommand(p *commands.KnParams) *cobra.Command {

data, dataBase64, err := getDataFields(&updateFlags)
if err != nil {
fmt.Fprintf(cmd.OutOrStderr(), "Ping source creation failed with error: %v", err)
fmt.Fprintf(cmd.OutOrStderr(), "cannot create PingSource %q in namespace "+
"%q because: %s", name, namespace, err)
return err
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/kn/commands/source/ping/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ func NewPingDescribeCommand(p *commands.KnParams) *cobra.Command {
func writePingSource(dw printers.PrefixWriter, source *clientsourcesv1beta2.PingSource, printDetails bool) {
commands.WriteMetadata(dw, &source.ObjectMeta, printDetails)
dw.WriteAttribute("Schedule", source.Spec.Schedule)
dw.WriteAttribute("Data", source.Spec.Data)
if source.Spec.DataBase64 != "" {
dw.WriteAttribute("DataBase64", source.Spec.DataBase64)
} else {
dw.WriteAttribute("Data", source.Spec.Data)
}
}

func writeCeOverrides(dw printers.PrefixWriter, ceOverrides map[string]string) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/kn/commands/source/ping/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func NewPingUpdateCommand(p *commands.KnParams) *cobra.Command {

data, dataBase64, err := getDataFields(&updateFlags)
if err != nil {
fmt.Fprintf(cmd.OutOrStderr(), "Ping source update failed with error: %v", err)
fmt.Fprintf(cmd.OutOrStderr(), "cannot create PingSource %q in namespace "+
"%q because: %s", name, namespace, err)
return err
}

Expand Down
26 changes: 26 additions & 0 deletions test/e2e/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ func TestSourcePing(t *testing.T) {
mymsg := "This is a message from Ping."
pingSourceCreate(r, "testpingsource3", "*/1 * * * *", mymsg, "ksvc:testsvc1")
verifyPingSourceDescribe(r, "testpingsource3", "*/1 * * * *", mymsg, "testsvc1")

t.Log("create Ping source with base64 data without encoding flag")

pingSourceCreate(r, "testpingsource4", "* * * * */1", "cGluZw==", "ksvc:testsvc1")
verifyPingSourceDescribe(r, "testpingsource4", "* * * * */1", "cGluZw==", "testsvc1")

t.Log("create Ping source with text data and encoding flag")
pingSourceCreateWithEncoding(r, "testpingsource6", "* * * * */1", "cGluZw==", "ksvc:testsvc1", "text")
verifyPingSourceDescribe(r, "testpingsource6", "* * * * */1", "cGluZw==", "testsvc1")

t.Log("update Ping source with base64 data and encoding flag")
pingSourceUpdateData(r, "testpingsource6", "cGluZw==", "base64")
verifyPingSourceDescribe(r, "testpingsource6", "* * * * */1", "cGluZw==", "testsvc1")
}

func pingSourceCreate(r *test.KnRunResultCollector, sourceName string, schedule string, data string, sink string) {
Expand All @@ -73,6 +86,13 @@ func pingSourceCreate(r *test.KnRunResultCollector, sourceName string, schedule
r.AssertNoError(out)
}

func pingSourceCreateWithEncoding(r *test.KnRunResultCollector, sourceName string, schedule string, data string, sink string, encoding string) {
out := r.KnTest().Kn().Run("source", "ping", "create", sourceName,
"--schedule", schedule, "--data", data, "--sink", sink, "--encoding", encoding)
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "ping", "source", sourceName, "created", "namespace", r.KnTest().Kn().Namespace()))
r.AssertNoError(out)
}

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()))
Expand All @@ -98,6 +118,12 @@ func pingSourceUpdateSink(r *test.KnRunResultCollector, sourceName string, sink
r.AssertNoError(out)
}

func pingSourceUpdateData(r *test.KnRunResultCollector, sourceName string, data string, encoding string) {
out := r.KnTest().Kn().Run("source", "ping", "update", sourceName, "--data", data, "--encoding", encoding)
assert.Check(r.T(), util.ContainsAll(out.Stdout, sourceName, "updated", "namespace", r.KnTest().Kn().Namespace()))
r.AssertNoError(out)
}

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))
Expand Down

0 comments on commit 1394f66

Please sign in to comment.