-
Notifications
You must be signed in to change notification settings - Fork 601
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
daemon, client, cmd/snap: implement snap start/stop/restart #3657
Changes from 1 commit
53f206e
4f27ccf
19e2be7
0e751f6
c8df78d
8b0a3b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,3 +187,186 @@ func (cs *clientSuite) TestClientLogsOpts(c *check.C) { | |
} | ||
} | ||
} | ||
|
||
func (cs *clientSuite) TestClientServiceStart(c *check.C) { | ||
cs.rsp = `{"type": "async", "status-code": 202, "change": "24"}` | ||
|
||
type tT struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. scenario? |
||
names []string | ||
opts client.StartOptions | ||
comment check.CommentInterface | ||
} | ||
|
||
var scs []tT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. scenarios? |
||
|
||
for _, names := range [][]string{ | ||
nil, {}, | ||
{"foo"}, | ||
{"foo", "bar", "baz"}, | ||
} { | ||
for _, opts := range []client.StartOptions{ | ||
{true}, | ||
{false}, | ||
} { | ||
scs = append(scs, tT{ | ||
names: names, | ||
opts: opts, | ||
comment: check.Commentf("{%q; %#v}", names, opts), | ||
}) | ||
} | ||
} | ||
|
||
for _, sc := range scs { | ||
id, err := cs.cli.Start(sc.names, sc.opts) | ||
if len(sc.names) == 0 { | ||
c.Check(id, check.Equals, "", sc.comment) | ||
c.Check(err, check.Equals, client.ErrNoNames, sc.comment) | ||
c.Check(cs.req, check.IsNil, sc.comment) // i.e. the request was never done | ||
} else { | ||
c.Assert(err, check.IsNil, sc.comment) | ||
c.Check(id, check.Equals, "24", sc.comment) | ||
c.Check(cs.req.URL.Path, check.Equals, "/v2/apps", sc.comment) | ||
c.Check(cs.req.Method, check.Equals, "POST", sc.comment) | ||
c.Check(cs.req.URL.Query(), check.HasLen, 0, sc.comment) | ||
|
||
inames := make([]interface{}, len(sc.names)) | ||
for i, name := range sc.names { | ||
inames[i] = interface{}(name) | ||
} | ||
|
||
var reqOp map[string]interface{} | ||
c.Assert(json.NewDecoder(cs.req.Body).Decode(&reqOp), check.IsNil, sc.comment) | ||
if sc.opts.Enable { | ||
c.Check(len(reqOp), check.Equals, 3, sc.comment) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is 2 vs 3 below? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. number of properties? maybe we should have testutil.SortedKeys(interface{} /*map*/) []string for cases like this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the boolean option isn't sent over the wire when false, so there's one less element in the decoded map. |
||
c.Check(reqOp["enable"], check.Equals, true, sc.comment) | ||
} else { | ||
c.Check(len(reqOp), check.Equals, 2, sc.comment) | ||
c.Check(reqOp["enable"], check.IsNil, sc.comment) | ||
} | ||
c.Check(reqOp["action"], check.Equals, "start", sc.comment) | ||
c.Check(reqOp["names"], check.DeepEquals, inames, sc.comment) | ||
} | ||
} | ||
} | ||
|
||
func (cs *clientSuite) TestClientServiceStop(c *check.C) { | ||
cs.rsp = `{"type": "async", "status-code": 202, "change": "24"}` | ||
|
||
type tT struct { | ||
names []string | ||
opts client.StopOptions | ||
comment check.CommentInterface | ||
} | ||
|
||
var scs []tT | ||
|
||
for _, names := range [][]string{ | ||
nil, {}, | ||
{"foo"}, | ||
{"foo", "bar", "baz"}, | ||
} { | ||
for _, opts := range []client.StopOptions{ | ||
{true}, | ||
{false}, | ||
} { | ||
scs = append(scs, tT{ | ||
names: names, | ||
opts: opts, | ||
comment: check.Commentf("{%q; %#v}", names, opts), | ||
}) | ||
} | ||
} | ||
|
||
for _, sc := range scs { | ||
id, err := cs.cli.Stop(sc.names, sc.opts) | ||
if len(sc.names) == 0 { | ||
c.Check(id, check.Equals, "", sc.comment) | ||
c.Check(err, check.Equals, client.ErrNoNames, sc.comment) | ||
c.Check(cs.req, check.IsNil, sc.comment) // i.e. the request was never done | ||
} else { | ||
c.Assert(err, check.IsNil, sc.comment) | ||
c.Check(id, check.Equals, "24", sc.comment) | ||
c.Check(cs.req.URL.Path, check.Equals, "/v2/apps", sc.comment) | ||
c.Check(cs.req.Method, check.Equals, "POST", sc.comment) | ||
c.Check(cs.req.URL.Query(), check.HasLen, 0, sc.comment) | ||
|
||
inames := make([]interface{}, len(sc.names)) | ||
for i, name := range sc.names { | ||
inames[i] = interface{}(name) | ||
} | ||
|
||
var reqOp map[string]interface{} | ||
c.Assert(json.NewDecoder(cs.req.Body).Decode(&reqOp), check.IsNil, sc.comment) | ||
if sc.opts.Disable { | ||
c.Check(len(reqOp), check.Equals, 3, sc.comment) | ||
c.Check(reqOp["disable"], check.Equals, true, sc.comment) | ||
} else { | ||
c.Check(len(reqOp), check.Equals, 2, sc.comment) | ||
c.Check(reqOp["disable"], check.IsNil, sc.comment) | ||
} | ||
c.Check(reqOp["action"], check.Equals, "stop", sc.comment) | ||
c.Check(reqOp["names"], check.DeepEquals, inames, sc.comment) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be nice to de-duplicate those tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I considered it, but couldn't find a way that wasn't too "magic" (either needing to fiddle with If I missed an approach, let me know. |
||
} | ||
} | ||
|
||
func (cs *clientSuite) TestClientServiceRestart(c *check.C) { | ||
cs.rsp = `{"type": "async", "status-code": 202, "change": "24"}` | ||
|
||
type tT struct { | ||
names []string | ||
opts client.RestartOptions | ||
comment check.CommentInterface | ||
} | ||
|
||
var scs []tT | ||
|
||
for _, names := range [][]string{ | ||
nil, {}, | ||
{"foo"}, | ||
{"foo", "bar", "baz"}, | ||
} { | ||
for _, opts := range []client.RestartOptions{ | ||
{true}, | ||
{false}, | ||
} { | ||
scs = append(scs, tT{ | ||
names: names, | ||
opts: opts, | ||
comment: check.Commentf("{%q; %#v}", names, opts), | ||
}) | ||
} | ||
} | ||
|
||
for _, sc := range scs { | ||
id, err := cs.cli.Restart(sc.names, sc.opts) | ||
if len(sc.names) == 0 { | ||
c.Check(id, check.Equals, "", sc.comment) | ||
c.Check(err, check.Equals, client.ErrNoNames, sc.comment) | ||
c.Check(cs.req, check.IsNil, sc.comment) // i.e. the request was never done | ||
} else { | ||
c.Assert(err, check.IsNil, sc.comment) | ||
c.Check(id, check.Equals, "24", sc.comment) | ||
c.Check(cs.req.URL.Path, check.Equals, "/v2/apps", sc.comment) | ||
c.Check(cs.req.Method, check.Equals, "POST", sc.comment) | ||
c.Check(cs.req.URL.Query(), check.HasLen, 0, sc.comment) | ||
|
||
inames := make([]interface{}, len(sc.names)) | ||
for i, name := range sc.names { | ||
inames[i] = interface{}(name) | ||
} | ||
|
||
var reqOp map[string]interface{} | ||
c.Assert(json.NewDecoder(cs.req.Body).Decode(&reqOp), check.IsNil, sc.comment) | ||
if sc.opts.Reload { | ||
c.Check(len(reqOp), check.Equals, 3, sc.comment) | ||
c.Check(reqOp["reload"], check.Equals, true, sc.comment) | ||
} else { | ||
c.Check(len(reqOp), check.Equals, 2, sc.comment) | ||
c.Check(reqOp["reload"], check.IsNil, sc.comment) | ||
} | ||
c.Check(reqOp["action"], check.Equals, "restart", sc.comment) | ||
c.Check(reqOp["names"], check.DeepEquals, inames, sc.comment) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to document the difference between the two.