github.com/rigado/snapd@v2.42.5-go-mod+incompatible/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 "io/ioutil" 25 26 "gopkg.in/check.v1" 27 ) 28 29 func (cs *clientSuite) TestClientCreateCohortsEndpoint(c *check.C) { 30 cs.cli.CreateCohorts([]string{"foo", "bar"}) 31 c.Check(cs.req.Method, check.Equals, "POST") 32 c.Check(cs.req.URL.Path, check.Equals, "/v2/cohorts") 33 34 body, err := ioutil.ReadAll(cs.req.Body) 35 c.Assert(err, check.IsNil) 36 var jsonBody map[string]interface{} 37 err = json.Unmarshal(body, &jsonBody) 38 c.Assert(err, check.IsNil) 39 c.Check(jsonBody, check.DeepEquals, map[string]interface{}{ 40 "action": "create", 41 "snaps": []interface{}{"foo", "bar"}, 42 }) 43 } 44 45 func (cs *clientSuite) TestClientCreateCohorts(c *check.C) { 46 cs.rsp = `{ 47 "type": "sync", 48 "status-code": 200, 49 "result": {"foo": "xyzzy", "bar": "what-what"} 50 }` 51 cohorts, err := cs.cli.CreateCohorts([]string{"foo", "bar"}) 52 c.Assert(err, check.IsNil) 53 c.Check(cohorts, check.DeepEquals, map[string]string{ 54 "foo": "xyzzy", 55 "bar": "what-what", 56 }) 57 58 body, err := ioutil.ReadAll(cs.req.Body) 59 c.Assert(err, check.IsNil) 60 var jsonBody map[string]interface{} 61 err = json.Unmarshal(body, &jsonBody) 62 c.Assert(err, check.IsNil) 63 c.Check(jsonBody, check.DeepEquals, map[string]interface{}{ 64 "action": "create", 65 "snaps": []interface{}{"foo", "bar"}, 66 }) 67 }