func (cs *clientSuite) TestClientIntegration(c *check.C) { c.Assert(os.MkdirAll(filepath.Dir(dirs.SnapdSocket), 0755), check.IsNil) l, err := net.Listen("unix", dirs.SnapdSocket) if err != nil { c.Fatalf("unable to listen on %q: %v", dirs.SnapdSocket, err) } f := func(w http.ResponseWriter, r *http.Request) { c.Check(r.URL.Path, check.Equals, "/v2/system-info") c.Check(r.URL.RawQuery, check.Equals, "") fmt.Fprintln(w, `{"type":"sync", "result":{"store":"X"}}`) } srv := &httptest.Server{ Listener: l, Config: &http.Server{Handler: http.HandlerFunc(f)}, } srv.Start() defer srv.Close() cli := client.New(nil) si, err := cli.SysInfo() c.Check(err, check.IsNil) c.Check(si.Store, check.Equals, "X") }
func (cs *clientSuite) SetUpTest(c *check.C) { cs.cli = client.New() cs.cli.SetDoer(cs) cs.err = nil cs.rsp = "" cs.req = nil cs.header = nil cs.status = http.StatusOK }
func (x *cmdAddCap) Execute(args []string) error { cap := &client.Capability{ Name: x.Name, Label: x.Label, Type: x.Type, Attrs: AttributePairSliceToMap(x.Attrs), } return client.New().AddCapability(cap) }
func (x *cmdAssert) Execute(args []string) error { assertFile := x.assertOptions.AssertionFile assertData, err := ioutil.ReadFile(assertFile) if err != nil { return err } return client.New().Assert(assertData) }
func (cs *clientSuite) SetUpTest(c *check.C) { cs.cli = client.New(nil) cs.cli.SetDoer(cs) cs.err = nil cs.rsp = "" cs.req = nil cs.header = nil cs.status = http.StatusOK dirs.SetRootDir(c.MkDir()) }
func (x *cmdListCaps) Execute(args []string) error { cli := client.New() caps, err := cli.Capabilities() if err != nil { return err } w := tabwriter.NewWriter(os.Stdout, 0, 4, 1, ' ', 0) fmt.Fprintln(w, "Name\tLabel\tType") for _, cap := range caps { fmt.Fprintf(w, "%s\t%s\t%s\n", cap.Name, cap.Label, cap.Type) } w.Flush() return nil }
func (cs *clientSuite) TestNewCustomURL(c *check.C) { f := func(w http.ResponseWriter, r *http.Request) { c.Check(r.URL.Path, check.Equals, "/v2/system-info") c.Check(r.URL.RawQuery, check.Equals, "") fmt.Fprintln(w, `{"type":"sync", "result":{"store":"X"}}`) } srv := httptest.NewServer(http.HandlerFunc(f)) defer srv.Close() cli := client.New(&client.Config{BaseURL: srv.URL}) c.Assert(cli, check.Not(check.IsNil)) si, err := cli.SysInfo() c.Check(err, check.IsNil) c.Check(si.Store, check.Equals, "X") }
// Client returns a new client using ClientConfig as configuration. func Client() *client.Client { return client.New(&ClientConfig) }
func (cs *clientSuite) TestNewPanics(c *check.C) { c.Assert(func() { client.New(&client.Config{BaseURL: ":"}) }, check.PanicMatches, `cannot parse server base URL: ":" \(parse :: missing protocol scheme\)`) }
func (x *cmdRemoveCap) Execute(args []string) error { return client.New().RemoveCapability(x.Name) }