|
20 | 20 | package main_test |
21 | 21 |
|
22 | 22 | import ( |
| 23 | + "encoding/json" |
23 | 24 | "fmt" |
24 | 25 | "net/http" |
25 | 26 | "strings" |
26 | 27 |
|
27 | 28 | "gopkg.in/check.v1" |
28 | 29 |
|
29 | 30 | snap "github.com/snapcore/snapd/cmd/snap" |
| 31 | + "github.com/snapcore/snapd/client" |
30 | 32 | ) |
31 | 33 |
|
32 | 34 | var mockChangeJSON = `{"type": "sync", "result": { |
@@ -232,6 +234,30 @@ Doing +2016-04-21T01:02:03Z +2016-04-21T01:02:04Z +some summary \(50.00%\) |
232 | 234 | c.Check(s.Stderr(), check.Equals, "") |
233 | 235 | } |
234 | 236 |
|
| 237 | +func (s *SnapSuite) TestTasksJSON(c *check.C) { |
| 238 | + s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) { |
| 239 | + c.Check(r.Method, check.Equals, "GET") |
| 240 | + c.Check(r.URL.Path, check.Equals, "/v2/changes/42") |
| 241 | + fmt.Fprintln(w, mockChangeJSON) |
| 242 | + }) |
| 243 | + |
| 244 | + rest, err := snap.Parser(snap.Client()).ParseArgs([]string{"tasks", "--format=json", "42"}) |
| 245 | + c.Assert(err, check.IsNil) |
| 246 | + c.Assert(rest, check.DeepEquals, []string{}) |
| 247 | + |
| 248 | + var chg client.Change |
| 249 | + c.Assert(json.Unmarshal([]byte(s.Stdout()), &chg), check.IsNil) |
| 250 | + c.Check(chg.ID, check.Equals, "uno") |
| 251 | + c.Check(chg.Kind, check.Equals, "foo") |
| 252 | + c.Check(chg.Summary, check.Equals, "...") |
| 253 | + c.Check(chg.Status, check.Equals, "Do") |
| 254 | + c.Check(chg.Ready, check.Equals, false) |
| 255 | + c.Assert(chg.Tasks, check.HasLen, 1) |
| 256 | + c.Check(chg.Tasks[0].Kind, check.Equals, "bar") |
| 257 | + c.Check(chg.Tasks[0].Summary, check.Equals, "some summary") |
| 258 | + c.Check(chg.Tasks[0].Status, check.Equals, "Do") |
| 259 | +} |
| 260 | + |
235 | 261 | func (s *SnapSuite) TestNoChanges(c *check.C) { |
236 | 262 | n := 0 |
237 | 263 | s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) { |
|
0 commit comments