Skip to content

Commit

Permalink
fake client
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivam Mukhade committed Jun 11, 2020
1 parent bc10874 commit 91f5067
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/cmd/pipelinerun/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package pipelinerun

import (
"errors"
"fmt"
"strings"
"testing"
Expand All @@ -32,7 +33,10 @@ import (
"gotest.tools/v3/golden"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic"
ktesting "k8s.io/client-go/testing"
"knative.dev/pkg/apis"
)

Expand Down Expand Up @@ -129,6 +133,33 @@ func TestListPipelineRuns(t *testing.T) {
t.Errorf("unable to create dynamic client: %v", err)
}

tdc3 := testDynamic.Options{
PrependReactors: []testDynamic.PrependOpt{
{
Resource: "pipelinerun",
Verb: "list",
Action: func(action ktesting.Action) (handled bool, ret runtime.Object, err error) {
listAction := action.(ktesting.ListAction)
fieldRestrictions := listAction.GetListRestrictions().Fields.String()
if fieldRestrictions != "metadata.name=pr0-1" {
return false, nil, errors.New("fake list taskrun error")
}
return true, prs[0], nil
},
},
},
}
dc3, err := tdc3.Client(
cb.UnstructuredPR(prs[0], version),
cb.UnstructuredPR(prs[1], version),
cb.UnstructuredPR(prs[2], version),
cb.UnstructuredPR(prs[3], version),
cb.UnstructuredPR(prs[4], version),
)
if err != nil {
t.Errorf("unable to create dynamic client: %v", err)
}

tests := []struct {
name string
command *cobra.Command
Expand All @@ -141,6 +172,12 @@ func TestListPipelineRuns(t *testing.T) {
args: []string{"list", "-n", "invalid"},
wantError: true,
},
{
name: "list pipelinerun by field-selector",
command: command(t, prs, clock.Now(), ns, version, dc3),
args: []string{"list", "-n", "namespace", "--field-selector", "metadata.name=pr0-1"},
wantError: false,
},
{
name: "by pipeline name",
command: command(t, prs, clock.Now(), ns, version, dc1),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NAME STARTED DURATION STATUS
pr0-1 --- --- ---
pr3-1 --- --- ---
pr1-1 59 minutes ago 1 minute Succeeded
pr2-2 2 hours ago 1 minute Failed
pr2-1 3 hours ago --- Succeeded(Running)

0 comments on commit 91f5067

Please sign in to comment.