Пример #1
0
func (s *cmdSuite) TestNewFetch(c *gc.C) {
	in := bytes.NewBufferString("hello world")
	var out bytes.Buffer
	fetchIn, newOut := io.Pipe()

	newCtx := &StubContext{
		flags: map[string]interface{}{
			"url":  s.server.URL,
			"home": s.home,
		},
		stdin: in, stdout: newOut,
	}
	newCmd := cmd.NewNewCommand()
	fetchCtx := &StubContext{
		flags: map[string]interface{}{
			"url":  s.server.URL,
			"home": s.home,
		},
		stdin: fetchIn, stdout: &out,
	}
	fetchCmd := cmd.NewFetchCommand()

	var t tomb.Tomb
	t.Go(func() error {
		return newCmd.Do(newCtx)
	})
	t.Go(func() error {
		return fetchCmd.Do(fetchCtx)
	})
	c.Assert(t.Wait(), gc.IsNil)
	c.Assert(out.String(), gc.Equals, "hello world")
}
Пример #2
0
func (s *cmdSuite) TestDelete(c *gc.C) {
	in := bytes.NewBufferString("hello world")
	var out bytes.Buffer
	flags := map[string]interface{}{
		"url":  s.server.URL,
		"home": s.home,
	}
	// create
	c.Assert(cmd.NewNewCommand().Do(&StubContext{
		flags: flags,
		stdin: in, stdout: &out,
	}), gc.IsNil)
	// then delete
	c.Assert(cmd.NewDeleteCommand().Do(&StubContext{
		flags: flags,
		stdin: bytes.NewBuffer(out.Bytes()),
	}), gc.IsNil)
	// now it's gone
	c.Assert(cmd.NewFetchCommand().Do(&StubContext{
		flags: flags,
		stdin: bytes.NewBuffer(out.Bytes()),
	}), gc.ErrorMatches, `^404 Not Found.*`)
	c.Assert(cmd.NewDeleteCommand().Do(&StubContext{
		flags: flags,
		stdin: bytes.NewBuffer(out.Bytes()),
	}), gc.ErrorMatches, `^404 Not Found.*`)
}
Пример #3
0
func main() {
	app := cli.NewApp()
	app.Name = "oo"
	app.Usage = "oo [command] [args]"
	app.Commands = []cli.Command{
		cmd.NewNewCommand().CLICommand(),
		cmd.NewFetchCommand().CLICommand(),
		cmd.NewCondCommand().CLICommand(),
		cmd.NewDeleteCommand().CLICommand(),
		cmd.NewKeyCommand().CLICommand(),
	}
	app.Run(os.Args)
}