示例#1
0
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")
}
示例#2
0
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
}
示例#3
0
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)
}
示例#4
0
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)
}
示例#5
0
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())
}
示例#6
0
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
}
示例#7
0
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")
}
示例#8
0
文件: main.go 项目: dholbach/snappy
// Client returns a new client using ClientConfig as configuration.
func Client() *client.Client {
	return client.New(&ClientConfig)
}
示例#9
0
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\)`)
}
示例#10
0
func (x *cmdRemoveCap) Execute(args []string) error {
	return client.New().RemoveCapability(x.Name)
}