-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrpcserver_test.go
65 lines (59 loc) · 1.37 KB
/
rpcserver_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"reflect"
"testing"
"time"
)
type fakeQueue struct {
queued []*Command
now time.Time
}
func (q *fakeQueue) Enqueue(cmd *Command) (*EnqueuedCommand, error) {
q.queued = append(q.queued, cmd)
return &EnqueuedCommand{Command: *cmd, EnqueuedAt: q.now}, nil
}
func TestServer_Enqueue(t *testing.T) {
type args struct {
cmd *Command
reply *EnqueuedCommand
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "enqueues command",
args: args{
cmd: &Command{
WorkingDirectory: "/cwd",
Command: "sleep",
Args: []string{"1"},
Env: []string{"FOO=BAR"},
},
reply: &EnqueuedCommand{},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fq := &fakeQueue{
queued: []*Command{},
now: time.Now(),
}
s := &Server{
commandQueue: fq,
}
if err := s.Enqueue(tt.args.cmd, tt.args.reply); (err != nil) != tt.wantErr {
t.Errorf("Enqueue() error = %v, wantErr %v", err, tt.wantErr)
}
if len(fq.queued) != 1 {
t.Errorf("Enqueue() queued = %v, want %v", fq.queued, 1)
}
if reflect.DeepEqual(tt.args.reply, &EnqueuedCommand{Command: *tt.args.cmd, EnqueuedAt: fq.now}) != true {
t.Errorf("Enqueue() reply.Command = %v, want %v", tt.args.reply.Command, tt.args.cmd)
}
})
}
}