This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
cli_test.go
95 lines (73 loc) · 1.97 KB
/
cli_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) 2012 VMware, Inc.
package gonit_test
import (
"fmt"
. "github.com/cloudfoundry/gonit"
"github.com/cloudfoundry/gonit/test/helper"
. "launchpad.net/gocheck"
"net/rpc"
)
type CliSuite struct{}
var _ = Suite(&CliSuite{})
var mockAPI = &MockAPI{api: &API{}}
func init() {
rpc.Register(mockAPI)
}
type MockAPI struct {
api *API
}
func (*MockAPI) StopProcess(name string, r *ActionResult) error {
if name == "foo" {
return nil
}
return fmt.Errorf("Unknown service %s", name)
}
func (*MockAPI) StartGroup(name string, r *ActionResult) error {
if name == "vcap" {
return nil
}
return fmt.Errorf("Unknown service group %s", name)
}
func (*MockAPI) UnmonitorAll(unused interface{}, r *ActionResult) error {
return nil
}
func (m *MockAPI) About(args interface{}, about *About) error {
return m.api.About(args, about)
}
// run tests via RPC or local reflection
func runTests(c *C, client CliClient) {
method, name := RpcArgs("stop", "foo", false)
_, err := client.Call(method, name)
c.Check(err, IsNil)
method, name = RpcArgs("stop", "bar", false)
_, err = client.Call(method, name)
c.Check(err, NotNil)
method, name = RpcArgs("unmonitor", "all", false)
_, err = client.Call(method, name)
c.Check(err, IsNil)
method, name = RpcArgs("start", "vcap", true)
_, err = client.Call(method, name)
c.Check(err, IsNil)
method, name = RpcArgs("start", "bar", true)
_, err = client.Call(method, name)
c.Check(err, NotNil)
method, name = RpcArgs("about", "", false)
reply, err := client.Call(method, name)
c.Check(err, IsNil)
about, ok := reply.(*About)
c.Check(true, Equals, ok)
c.Check(VERSION, Equals, about.Version)
reply, err = client.Call("ENOENT", "")
c.Check(err, NotNil)
}
func (s *CliSuite) TestRemote(c *C) {
err := helper.WithRpcServer(func(rc *rpc.Client) {
client := NewRemoteClient(rc, mockAPI)
runTests(c, client)
})
c.Check(err, IsNil)
}
func (s *CliSuite) TestLocal(c *C) {
client := NewLocalClient(mockAPI)
runTests(c, client)
}