Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description to task, clustertask, condition list #787

Merged
merged 1 commit into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/cmd/clustertask/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()),
)
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/clustertask/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions pkg/cmd/condition/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()),
)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/condition/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
5 changes: 3 additions & 2 deletions pkg/cmd/task/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()),
)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/task/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
11 changes: 7 additions & 4 deletions pkg/cmd/task/testdata/TestTaskList_Only_Tasks.golden
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions pkg/formatted/description.go
Original file line number Diff line number Diff line change
@@ -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
}
58 changes: 58 additions & 0 deletions pkg/formatted/description_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
5 changes: 3 additions & 2 deletions test/e2e/build_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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),
)
}
Expand Down