コード例 #1
0
ファイル: put_test.go プロジェクト: Jane4PKU/bosh
func init() {
	Describe("Testing with Ginkgo", func() {
		It("put run with valid args", func() {
			pwd, _ := os.Getwd()
			sourceFilePath := filepath.Join(pwd, "../../../../fixtures/cat.jpg")
			targetBlob := "some-other-awesome-guid"
			serverWasHit := false

			handler := func(w http.ResponseWriter, r *http.Request) {
				serverWasHit = true
				req := testcmd.NewHTTPRequest(r)

				username, password, err := req.ExtractBasicAuth()

				Expect(err).ToNot(HaveOccurred())
				Expect(req.URL.Path).To(Equal("/d1/" + targetBlob))
				Expect(req.Method).To(Equal("PUT"))
				Expect(username).To(Equal("some user"))
				Expect(password).To(Equal("some pwd"))

				expectedBytes := fileBytes(sourceFilePath)
				actualBytes, _ := ioutil.ReadAll(r.Body)
				Expect(expectedBytes).To(Equal(actualBytes))

				w.WriteHeader(200)
			}

			ts := httptest.NewServer(http.HandlerFunc(handler))
			defer ts.Close()

			config := davconf.Config{
				User:     "******",
				Password: "******",
				Endpoint: ts.URL,
			}

			err := runPut(config, []string{sourceFilePath, targetBlob})
			Expect(err).ToNot(HaveOccurred())
			Expect(serverWasHit).To(BeTrue())
		})
		It("put run with incorrect arg count", func() {

			config := davconf.Config{}
			err := runPut(config, []string{})

			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("Incorrect usage"))
		})
	})
}
コード例 #2
0
ファイル: get_test.go プロジェクト: Jane4PKU/bosh
func init() {
	Describe("Testing with Ginkgo", func() {
		It("get run with valid args", func() {
			requestedBlob := "0ca907f2-dde8-4413-a304-9076c9d0978b"
			targetFilePath := filepath.Join(os.TempDir(), "testRunGetCommand.txt")
			defer os.RemoveAll(targetFilePath)

			handler := func(w http.ResponseWriter, r *http.Request) {
				req := testcmd.NewHTTPRequest(r)

				username, password, err := req.ExtractBasicAuth()

				Expect(err).ToNot(HaveOccurred())
				Expect(req.URL.Path).To(Equal("/0d/" + requestedBlob))
				Expect(req.Method).To(Equal("GET"))
				Expect(username).To(Equal("some user"))
				Expect(password).To(Equal("some pwd"))

				w.Write([]byte("this is your blob"))
			}

			ts := httptest.NewServer(http.HandlerFunc(handler))
			defer ts.Close()

			config := davconf.Config{
				User:     "******",
				Password: "******",
				Endpoint: ts.URL,
			}

			err := runGet(config, []string{requestedBlob, targetFilePath})
			Expect(err).ToNot(HaveOccurred())
			Expect(getFileContent(targetFilePath)).To(Equal("this is your blob"))
		})
		It("get run with incorrect arg count", func() {

			config := davconf.Config{}
			err := runGet(config, []string{})

			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("Incorrect usage"))
		})
	})
}
コード例 #3
0
	return content
}

var _ = Describe("PutCmd", func() {
	Describe("Run", func() {
		It("with valid args", func() {
			pwd, err := os.Getwd()
			Expect(err).ToNot(HaveOccurred())

			sourceFilePath := filepath.Join(pwd, "../../../../fixtures/cat.jpg")
			targetBlob := "some-other-awesome-guid"
			serverWasHit := false

			handler := func(w http.ResponseWriter, r *http.Request) {
				serverWasHit = true
				req := testcmd.NewHTTPRequest(r)

				username, password, err := req.ExtractBasicAuth()
				Expect(err).ToNot(HaveOccurred())
				Expect(req.URL.Path).To(Equal("/d1/" + targetBlob))
				Expect(req.Method).To(Equal("PUT"))
				Expect(username).To(Equal("some user"))
				Expect(password).To(Equal("some pwd"))

				expectedBytes := fileBytes(sourceFilePath)
				actualBytes, _ := ioutil.ReadAll(r.Body)
				Expect(expectedBytes).To(Equal(actualBytes))

				w.WriteHeader(200)
			}