diff --git a/pkg/cmd/clustertask/list.go b/pkg/cmd/clustertask/list.go index c1bc61aa6..aa9261d91 100644 --- a/pkg/cmd/clustertask/list.go +++ b/pkg/cmd/clustertask/list.go @@ -33,8 +33,8 @@ import ( const ( emptyMsg = "No clustertasks found" - header = "NAME\tAGE" - body = "%s\t%s\n" + header = "NAME\tDESCRIPTION\tAGE" + body = "%s\t%s\t%s\n" ) func listCommand(p cli.Params) *cobra.Command { @@ -94,6 +94,7 @@ func printClusterTaskDetails(s *cli.Stream, p cli.Params) error { for _, clustertask := range clustertasks.Items { fmt.Fprintf(w, body, clustertask.Name, + formatted.FormatDesc(clustertask.Spec.Description), formatted.Age(&clustertask.CreationTimestamp, p.Time()), ) } diff --git a/pkg/cmd/clustertask/list_test.go b/pkg/cmd/clustertask/list_test.go index cd88be0e7..0eeee0ca9 100644 --- a/pkg/cmd/clustertask/list_test.go +++ b/pkg/cmd/clustertask/list_test.go @@ -48,7 +48,9 @@ func TestClusterTaskListOnlyClusterTasks(t *testing.T) { clustertasks := []*v1alpha1.ClusterTask{ tb.ClusterTask("guavas", cb.ClusterTaskCreationTime(clock.Now().Add(-1*time.Minute))), tb.ClusterTask("avocados", cb.ClusterTaskCreationTime(clock.Now().Add(-20*time.Second))), - tb.ClusterTask("pineapple", cb.ClusterTaskCreationTime(clock.Now().Add(-512*time.Hour))), + tb.ClusterTask("pineapple", tb.ClusterTaskSpec(tb.TaskDescription("a test clustertask")), cb.ClusterTaskCreationTime(clock.Now().Add(-512*time.Hour))), + tb.ClusterTask("apple", tb.ClusterTaskSpec(tb.TaskDescription("a clustertask to test description")), cb.ClusterTaskCreationTime(clock.Now().Add(-513*time.Hour))), + tb.ClusterTask("mango", tb.ClusterTaskSpec(tb.TaskDescription("")), cb.ClusterTaskCreationTime(clock.Now().Add(-514*time.Hour))), } cs, _ := test.SeedTestData(t, pipelinetest.Data{ClusterTasks: clustertasks}) diff --git a/pkg/cmd/clustertask/testdata/TestClusterTaskListOnlyClusterTasks.golden b/pkg/cmd/clustertask/testdata/TestClusterTaskListOnlyClusterTasks.golden index 51c8aa37a..5c02bccd1 100644 --- a/pkg/cmd/clustertask/testdata/TestClusterTaskListOnlyClusterTasks.golden +++ b/pkg/cmd/clustertask/testdata/TestClusterTaskListOnlyClusterTasks.golden @@ -1,4 +1,6 @@ -NAME AGE -guavas 1 minute ago -avocados 20 seconds ago -pineapple 3 weeks ago +NAME DESCRIPTION AGE +guavas 1 minute ago +avocados 20 seconds ago +pineapple a test clustertask 3 weeks ago +apple a clustertask to te... 3 weeks ago +mango 3 weeks ago diff --git a/pkg/cmd/condition/list.go b/pkg/cmd/condition/list.go index 55ede7f6e..5b4dd53ff 100644 --- a/pkg/cmd/condition/list.go +++ b/pkg/cmd/condition/list.go @@ -32,8 +32,8 @@ import ( const ( emptyMsg = "No conditions found" - header = "NAME\tAGE" - body = "%s\t%s\n" + header = "NAME\tDESCRIPTION\tAGE" + body = "%s\t%s\t%s\n" ) func listCommand(p cli.Params) *cobra.Command { @@ -97,6 +97,7 @@ func printConditionDetails(s *cli.Stream, p cli.Params) error { for _, condition := range conditions.Items { fmt.Fprintf(w, body, condition.Name, + formatted.FormatDesc(condition.Spec.Description), formatted.Age(&condition.CreationTimestamp, p.Time()), ) } diff --git a/pkg/cmd/condition/list_test.go b/pkg/cmd/condition/list_test.go index 927d08b0b..1a132ddec 100644 --- a/pkg/cmd/condition/list_test.go +++ b/pkg/cmd/condition/list_test.go @@ -57,6 +57,9 @@ func TestConditionList(t *testing.T) { tb.Condition("condition1", "ns", cb.ConditionCreationTime(clock.Now().Add(-1*time.Minute))), tb.Condition("condition2", "ns", cb.ConditionCreationTime(clock.Now().Add(-20*time.Second))), tb.Condition("condition3", "ns", cb.ConditionCreationTime(clock.Now().Add(-512*time.Hour))), + tb.Condition("condition4", "ns", tb.ConditionSpec(tb.ConditionDescription("a test condition")), cb.ConditionCreationTime(clock.Now().Add(-513*time.Hour))), + tb.Condition("condition5", "ns", tb.ConditionSpec(tb.ConditionDescription("a test condition to check the trimming is working")), cb.ConditionCreationTime(clock.Now().Add(-514*time.Hour))), + tb.Condition("condition6", "ns", tb.ConditionSpec(tb.ConditionDescription("")), cb.ConditionCreationTime(clock.Now().Add(-516*time.Hour))), } s, _ := test.SeedTestData(t, pipelinetest.Data{Conditions: conditions, Namespaces: ns}) diff --git a/pkg/cmd/condition/testdata/TestConditionList-Found_conditions.golden b/pkg/cmd/condition/testdata/TestConditionList-Found_conditions.golden index d868c6c78..0ed88bc15 100644 --- a/pkg/cmd/condition/testdata/TestConditionList-Found_conditions.golden +++ b/pkg/cmd/condition/testdata/TestConditionList-Found_conditions.golden @@ -1,4 +1,7 @@ -NAME AGE -condition1 1 minute ago -condition2 20 seconds ago -condition3 3 weeks ago +NAME DESCRIPTION AGE +condition1 1 minute ago +condition2 20 seconds ago +condition3 3 weeks ago +condition4 a test condition 3 weeks ago +condition5 a test condition to... 3 weeks ago +condition6 3 weeks ago diff --git a/pkg/cmd/condition/testdata/TestConditionList-Specify_output_flag.golden b/pkg/cmd/condition/testdata/TestConditionList-Specify_output_flag.golden index 764177a1a..4f275438b 100644 --- a/pkg/cmd/condition/testdata/TestConditionList-Specify_output_flag.golden +++ b/pkg/cmd/condition/testdata/TestConditionList-Specify_output_flag.golden @@ -24,5 +24,31 @@ items: check: name: "" resources: {} +- metadata: + creationTimestamp: "1984-03-13T15:00:00Z" + name: condition4 + namespace: ns + spec: + check: + name: "" + resources: {} + description: a test condition +- metadata: + creationTimestamp: "1984-03-13T14:00:00Z" + name: condition5 + namespace: ns + spec: + check: + name: "" + resources: {} + description: a test condition to check the trimming is working +- metadata: + creationTimestamp: "1984-03-13T12:00:00Z" + name: condition6 + namespace: ns + spec: + check: + name: "" + resources: {} kind: ConditionList metadata: {} diff --git a/pkg/cmd/task/list.go b/pkg/cmd/task/list.go index d6ababd61..e544f436d 100644 --- a/pkg/cmd/task/list.go +++ b/pkg/cmd/task/list.go @@ -34,8 +34,8 @@ import ( const ( emptyMsg = "No tasks found" - header = "NAME\tAGE" - body = "%s\t%s\n" + header = "NAME\tDESCRIPTION\tAGE" + body = "%s\t%s\t%s\n" ) func listCommand(p cli.Params) *cobra.Command { @@ -98,6 +98,7 @@ func printTaskDetails(s *cli.Stream, p cli.Params) error { for _, task := range tasks.Items { fmt.Fprintf(w, body, task.Name, + formatted.FormatDesc(task.Spec.Description), formatted.Age(&task.CreationTimestamp, p.Time()), ) } diff --git a/pkg/cmd/task/list_test.go b/pkg/cmd/task/list_test.go index f2bcb6acf..2a82ab5a0 100644 --- a/pkg/cmd/task/list_test.go +++ b/pkg/cmd/task/list_test.go @@ -72,6 +72,9 @@ func TestTaskList_Only_Tasks(t *testing.T) { tb.Task("tomatoes", "namespace", cb.TaskCreationTime(clock.Now().Add(-1*time.Minute))), tb.Task("mangoes", "namespace", cb.TaskCreationTime(clock.Now().Add(-20*time.Second))), tb.Task("bananas", "namespace", cb.TaskCreationTime(clock.Now().Add(-512*time.Hour))), + tb.Task("apples", "namespace", tb.TaskSpec(tb.TaskDescription("")), cb.TaskCreationTime(clock.Now().Add(-513*time.Hour))), + tb.Task("potatoes", "namespace", tb.TaskSpec(tb.TaskDescription("a test task")), cb.TaskCreationTime(clock.Now().Add(-514*time.Hour))), + tb.Task("onionss", "namespace", tb.TaskSpec(tb.TaskDescription("a test task to test description of task")), cb.TaskCreationTime(clock.Now().Add(-515*time.Hour))), } ns := []*corev1.Namespace{ diff --git a/pkg/cmd/task/testdata/TestTaskList_Only_Tasks.golden b/pkg/cmd/task/testdata/TestTaskList_Only_Tasks.golden index d7b201f45..ff901f0af 100644 --- a/pkg/cmd/task/testdata/TestTaskList_Only_Tasks.golden +++ b/pkg/cmd/task/testdata/TestTaskList_Only_Tasks.golden @@ -1,4 +1,7 @@ -NAME AGE -tomatoes 1 minute ago -mangoes 20 seconds ago -bananas 3 weeks ago +NAME DESCRIPTION AGE +tomatoes 1 minute ago +mangoes 20 seconds ago +bananas 3 weeks ago +apples 3 weeks ago +potatoes a test task 3 weeks ago +onionss a test task to test... 3 weeks ago diff --git a/pkg/formatted/description.go b/pkg/formatted/description.go new file mode 100644 index 000000000..a5fdad8a5 --- /dev/null +++ b/pkg/formatted/description.go @@ -0,0 +1,24 @@ +// Copyright © 2019 The Tekton Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package formatted + +// If description is longer than 20 char then it will return +// initial 20 chars suffixed by ... +func FormatDesc(desc string) string { + if len(desc) > 20 { + return desc[0:19] + "..." + } + return desc +} diff --git a/pkg/formatted/description_test.go b/pkg/formatted/description_test.go new file mode 100644 index 000000000..af0707b1a --- /dev/null +++ b/pkg/formatted/description_test.go @@ -0,0 +1,58 @@ +// Copyright © 2019 The Tekton Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package formatted + +import "testing" + +func TestFormatDesc(t *testing.T) { + tests := []struct { + name string + input string + want string + }{ + { + name: "Empty string", + input: "", + want: "", + }, + { + name: "String with 19 char", + input: "test description to", + want: "test description to", + }, + { + name: "String with 20 chars", + input: "test description to ", + want: "test description to ", + }, + { + name: "String with 21 chars", + input: "test description to t", + want: "test description to...", + }, + { + name: "Long string", + input: "test description to test trimming", + want: "test description to...", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := FormatDesc(tt.input); got != tt.want { + t.Errorf("Input = %s, want %s", got, tt.want) + } + }) + } +} diff --git a/test/e2e/build_templates.go b/test/e2e/build_templates.go index 9e7b9f8cb..d50dd2803 100644 --- a/test/e2e/build_templates.go +++ b/test/e2e/build_templates.go @@ -246,8 +246,8 @@ func ListAllTasksOutput(t *testing.T, cs *Clients, td map[int]interface{}) strin t.Helper() const ( emptyMsg = "No tasks found" - header = "NAME\tAGE" - body = "%s\t%s\n" + header = "NAME\tDESCRIPTION\tAGE" + body = "%s\t%s\t%s\n" ) clock := clockwork.NewFakeClockAt(time.Now()) @@ -267,6 +267,7 @@ func ListAllTasksOutput(t *testing.T, cs *Clients, td map[int]interface{}) strin for _, task := range task.Items { fmt.Fprintf(w, body, task.Name, + formatted.FormatDesc(task.Spec.Description), formatted.Age(&task.CreationTimestamp, clock), ) }