gopkg.in/ubuntu-core/snappy.v0@v0.0.0-20210902073436-25a8614f10a6/client/cohort_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2019 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package client_test 21 22 import ( 23 "encoding/json" 24 "errors" 25 "io/ioutil" 26 27 "golang.org/x/xerrors" 28 "gopkg.in/check.v1" 29 ) 30 31 func (cs *clientSuite) TestClientCreateCohortsEndpoint(c *check.C) { 32 cs.cli.CreateCohorts([]string{"foo", "bar"}) 33 c.Check(cs.req.Method, check.Equals, "POST") 34 c.Check(cs.req.URL.Path, check.Equals, "/v2/cohorts") 35 36 body, err := ioutil.ReadAll(cs.req.Body) 37 c.Assert(err, check.IsNil) 38 var jsonBody map[string]interface{} 39 err = json.Unmarshal(body, &jsonBody) 40 c.Assert(err, check.IsNil) 41 c.Check(jsonBody, check.DeepEquals, map[string]interface{}{ 42 "action": "create", 43 "snaps": []interface{}{"foo", "bar"}, 44 }) 45 } 46 47 func (cs *clientSuite) TestClientCreateCohorts(c *check.C) { 48 cs.rsp = `{ 49 "type": "sync", 50 "status-code": 200, 51 "result": {"foo": "xyzzy", "bar": "what-what"} 52 }` 53 cohorts, err := cs.cli.CreateCohorts([]string{"foo", "bar"}) 54 c.Assert(err, check.IsNil) 55 c.Check(cohorts, check.DeepEquals, map[string]string{ 56 "foo": "xyzzy", 57 "bar": "what-what", 58 }) 59 60 body, err := ioutil.ReadAll(cs.req.Body) 61 c.Assert(err, check.IsNil) 62 var jsonBody map[string]interface{} 63 err = json.Unmarshal(body, &jsonBody) 64 c.Assert(err, check.IsNil) 65 c.Check(jsonBody, check.DeepEquals, map[string]interface{}{ 66 "action": "create", 67 "snaps": []interface{}{"foo", "bar"}, 68 }) 69 } 70 71 func (cs *clientSuite) TestClientCreateCohortsErrIsWrapped(c *check.C) { 72 cs.err = errors.New("boom") 73 _, err := cs.cli.CreateCohorts([]string{"foo", "bar"}) 74 var e xerrors.Wrapper 75 c.Assert(err, check.Implements, &e) 76 }