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

Display results in the output of task/taskrun describe command #1076

Merged
merged 1 commit into from
Jul 29, 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
11 changes: 11 additions & 0 deletions pkg/cmd/task/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ const describeTemplate = `{{decorate "bold" "Name"}}: {{ .Task.Name }}
{{- end }}
{{- end }}

{{decorate "results" ""}}{{decorate "underline bold" "Results\n"}}

{{- if eq (len .Task.Spec.Results) 0 }}
No results
{{- else }}
NAME DESCRIPTION
{{- range $result := .Task.Spec.Results }}
{{ decorate "bullet" $result.Name }} {{ formatDesc $result.Description }}
{{- end }}
{{- end }}

{{decorate "steps" ""}}{{decorate "underline bold" "Steps\n"}}

{{- if eq (len .Task.Spec.Steps) 0 }}
Expand Down
62 changes: 62 additions & 0 deletions pkg/cmd/task/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,3 +679,65 @@ func TestTaskV1beta1Describe_Full(t *testing.T) {
}
golden.Assert(t, out, fmt.Sprintf("%s.golden", t.Name()))
}

func TestTaskDescribe_With_Results(t *testing.T) {
tasks := []*v1beta1.Task{
{
ObjectMeta: metav1.ObjectMeta{
Namespace: "ns",
Name: "task-1",
},
Spec: v1beta1.TaskSpec{
Description: "a test description",
Steps: []v1beta1.Step{
{
Container: corev1.Container{
Name: "hello",
Image: "busybox",
},
},
},
Results: []v1beta1.TaskResult{
{
Name: "result-1",
Description: "This is a description for result 1",
},
{
Name: "result-2",
Description: "This is a description for result 2",
},
{
Name: "result-3",
},
},
},
},
}

namespaces := []*corev1.Namespace{
{
ObjectMeta: metav1.ObjectMeta{
Name: "ns",
},
},
}

version := "v1beta1"
tdc := testDynamic.Options{}
dynamic, err := tdc.Client(
cb.UnstructuredV1beta1T(tasks[0], version),
)
if err != nil {
t.Errorf("unable to create dynamic client: %v", err)
}

cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Tasks: tasks, Namespaces: namespaces})
cs.Pipeline.Resources = cb.APIResourceList(version, []string{"task", "taskrun"})
p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic}
task := Command(p)
out, err := test.ExecuteCommand(task, "desc", "task-1")
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
golden.Assert(t, out, fmt.Sprintf("%s.golden", t.Name()))
}
4 changes: 4 additions & 0 deletions pkg/cmd/task/testdata/TestTaskDescribe_Full.golden
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Params
print string params with sting t... somethingdifferent
output array [booms booms booms]

Results

No results

Steps

hello
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/task/testdata/TestTaskDescribe_OnlyName.golden
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Params

No params

Results

No results

Steps

No steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Params

No params

Results

No results

Steps

No steps
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/task/testdata/TestTaskDescribe_OnlyNameParams.golden
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Params
myprint string testing very long d... ---
myarray array ---

Results

No results

Steps

No steps
Expand Down
30 changes: 30 additions & 0 deletions pkg/cmd/task/testdata/TestTaskDescribe_With_Results.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Name: task-1
Namespace: ns
Description: a test description

Input Resources

No input resources

Output Resources

No output resources

Params

No params

Results

NAME DESCRIPTION
result-1 This is a descripti...
result-2 This is a descripti...
result-3

Steps

hello

Taskruns

No taskruns
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Params

No params

Results

No results

Steps

No steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Params

No params

Results

No results

Steps

No steps
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/task/testdata/TestTaskV1beta1Describe_Full.golden
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Params
print string somethingdifferent
output array [booms booms booms]

Results

No results

Steps

hello
Expand Down
69 changes: 69 additions & 0 deletions pkg/cmd/taskrun/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,3 +956,72 @@ func TestTaskRunDescribe_last(t *testing.T) {
}
golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name()))
}

func TestTaskRunDescribe_With_Results(t *testing.T) {
clock := clockwork.NewFakeClock()
taskRuns := []*v1beta1.TaskRun{
{
ObjectMeta: metav1.ObjectMeta{
Namespace: "ns",
Name: "tr-1",
Labels: map[string]string{"tekton.dev/task": "task-1"},
},
Spec: v1beta1.TaskRunSpec{
TaskRef: &v1beta1.TaskRef{
Name: "task-1",
},
},
Status: v1beta1.TaskRunStatus{
Status: duckv1beta1.Status{
Conditions: duckv1beta1.Conditions{
{
Status: corev1.ConditionFalse,
Reason: v1beta1.TaskRunReasonFailed.String(),
},
},
},
TaskRunStatusFields: v1beta1.TaskRunStatusFields{
StartTime: &metav1.Time{Time: clock.Now().Add(-10 * time.Minute)},
CompletionTime: &metav1.Time{Time: clock.Now().Add(-5 * time.Minute)},
TaskRunResults: []v1alpha1.TaskRunResult{
{
Name: "result-1",
Value: "value-1",
},
{
Name: "result-2",
Value: "value-2",
},
},
},
},
},
}

namespaces := []*corev1.Namespace{
{
ObjectMeta: metav1.ObjectMeta{
Name: "ns",
},
},
}

version := "v1beta1"
tdc := testDynamic.Options{}
dynamic, err := tdc.Client(
cb.UnstructuredV1beta1TR(taskRuns[0], version),
)
if err != nil {
t.Errorf("unable to create dynamic client: %v", err)
}
cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, TaskRuns: taskRuns})
cs.Pipeline.Resources = cb.APIResourceList(version, []string{"taskrun"})
p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic}
taskrun := Command(p)
got, err := test.ExecuteCommand(taskrun, "desc", "tr-1")

if err != nil {
t.Errorf("Unexpected error: %v", err)
}
golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name()))
}
36 changes: 36 additions & 0 deletions pkg/cmd/taskrun/testdata/TestTaskRunDescribe_With_Results.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Name: tr-1
Namespace: ns
Task Ref: task-1
Labels:
tekton.dev/task=task-1

Status

STARTED DURATION STATUS
10 minutes ago 5 minutes Failed

Input Resources

No input resources

Output Resources

No output resources

Params

No params

Results

NAME VALUE
result-1 value-1
result-2 value-2

Steps

No steps

Sidecars

No sidecars
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Params

No params

Results

No results

Steps

No steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Params

No params

Results

No results

Steps

No steps
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/taskrun/testdata/TestTaskRunDescribe_failed.golden
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Params

No params

Results

No results

Steps

No steps
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/taskrun/testdata/TestTaskRunDescribe_last.golden
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Params
input param
input2 param2

Results

No results

Steps

NAME STATUS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Params

No params

Results

No results

Steps

No steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Params
input param
input2 param2

Results

No results

Steps

NAME STATUS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Params

No params

Results

No results

Steps

No steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Params
input param
input2 param2

Results

No results

Steps

NAME STATUS
Expand Down
Loading