11package node
22
33import (
4+ "context"
45 "fmt"
56 "io/ioutil"
67 "testing"
@@ -66,13 +67,14 @@ func TestNodePsErrors(t *testing.T) {
6667
6768func TestNodePs (t * testing.T ) {
6869 testCases := []struct {
69- name string
70- args []string
71- flags map [string ]string
72- infoFunc func () (types.Info , error )
73- nodeInspectFunc func () (swarm.Node , []byte , error )
74- taskListFunc func (options types.TaskListOptions ) ([]swarm.Task , error )
75- taskInspectFunc func (taskID string ) (swarm.Task , []byte , error )
70+ name string
71+ args []string
72+ flags map [string ]string
73+ infoFunc func () (types.Info , error )
74+ nodeInspectFunc func () (swarm.Node , []byte , error )
75+ taskListFunc func (options types.TaskListOptions ) ([]swarm.Task , error )
76+ taskInspectFunc func (taskID string ) (swarm.Task , []byte , error )
77+ serviceInspectFunc func (ctx context.Context , serviceID string , opts types.ServiceInspectOptions ) (swarm.Service , []byte , error )
7678 }{
7779 {
7880 name : "simple" ,
@@ -91,6 +93,16 @@ func TestNodePs(t *testing.T) {
9193 }))),
9294 }, nil
9395 },
96+ serviceInspectFunc : func (ctx context.Context , serviceID string , opts types.ServiceInspectOptions ) (swarm.Service , []byte , error ) {
97+ return swarm.Service {
98+ ID : serviceID ,
99+ Spec : swarm.ServiceSpec {
100+ Annotations : swarm.Annotations {
101+ Name : serviceID ,
102+ },
103+ },
104+ }, []byte {}, nil
105+ },
94106 },
95107 {
96108 name : "with-errors" ,
@@ -108,14 +120,25 @@ func TestNodePs(t *testing.T) {
108120 WithStatus (Timestamp (time .Now ().Add (- 4 * time .Hour )), StatusErr ("a task error" ))),
109121 }, nil
110122 },
123+ serviceInspectFunc : func (ctx context.Context , serviceID string , opts types.ServiceInspectOptions ) (swarm.Service , []byte , error ) {
124+ return swarm.Service {
125+ ID : serviceID ,
126+ Spec : swarm.ServiceSpec {
127+ Annotations : swarm.Annotations {
128+ Name : serviceID ,
129+ },
130+ },
131+ }, []byte {}, nil
132+ },
111133 },
112134 }
113135 for _ , tc := range testCases {
114136 cli := test .NewFakeCli (& fakeClient {
115- infoFunc : tc .infoFunc ,
116- nodeInspectFunc : tc .nodeInspectFunc ,
117- taskInspectFunc : tc .taskInspectFunc ,
118- taskListFunc : tc .taskListFunc ,
137+ infoFunc : tc .infoFunc ,
138+ nodeInspectFunc : tc .nodeInspectFunc ,
139+ taskInspectFunc : tc .taskInspectFunc ,
140+ taskListFunc : tc .taskListFunc ,
141+ serviceInspectFunc : tc .serviceInspectFunc ,
119142 })
120143 cmd := newPsCommand (cli )
121144 cmd .SetArgs (tc .args )
0 commit comments