예제 #1
0
파일: app.go 프로젝트: phanle/s3cli
func (app app) Run(args []string) (err error) {
	args = args[1:]

	configPath, args, err := getConfigPath(args)
	if err != nil {
		return
	}

	s3Client, err := s3cliclient.GetS3Client(configPath)
	if err != nil {
		return
	}

	cmdFactory := s3clicmd.NewFactory(s3Client)
	cmdRunner := s3clicmd.NewRunner(cmdFactory)

	if len(args) < 1 {
		err = errors.New("Command missing")
		return
	}

	cmdName := args[0]
	cmdArgs := args[1:]
	err = cmdRunner.Run(cmdName, cmdArgs)
	return
}
예제 #2
0
파일: put_test.go 프로젝트: ric03uecS/s3cli
	fakeclient "s3cli/client/fakes"
	s3clicmd "s3cli/cmd"
)

var _ = Describe("getCmd", func() {
	var (
		client *fakeclient.FakeClient
		cmd    s3clicmd.Cmd
	)

	BeforeEach(func() {
		var err error

		client = &fakeclient.FakeClient{}
		factory := s3clicmd.NewFactory(client)

		cmd, err = factory.Create("put")
		Expect(err).ToNot(HaveOccurred())
	})

	Describe("Run", func() {
		Context("with enough arguments", func() {
			It("uploads blob", func() {
				err := cmd.Run([]string{"../../fixtures/cat.jpg", "my-cat.jpg"})
				Expect(err).ToNot(HaveOccurred())

				file := client.PutReaderReader.(*os.File)
				Expect(client.PutReaderPath).To(Equal("my-cat.jpg"))
				Expect(file.Name()).To(Equal("../../fixtures/cat.jpg"))
				Expect(client.PutReaderLength).To(Equal(int64(1718186)))