コード例 #1
0
		})

		It("returns an error on a bogus response body", func() {
			testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				Expect(r.URL.Path).To(Equal("/cloud_configs"))

				w.WriteHeader(http.StatusTeapot)
				w.Write([]byte("More info"))
			}))

			client := bosh.NewClient(bosh.Config{
				URL: testServer.URL,
			})

			bosh.SetBodyReader(func(io.Reader) ([]byte, error) {
				return nil, errors.New("a bad read happened")
			})

			err := client.UpdateCloudConfig([]byte(""))
			Expect(err).To(MatchError("a bad read happened"))
		})

		It("errors on an unexpected status code with body", func() {
			testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				Expect(r.URL.Path).To(Equal("/cloud_configs"))

				w.WriteHeader(http.StatusTeapot)
				w.Write([]byte("More info"))
			}))

			client := bosh.NewClient(bosh.Config{
コード例 #2
0
				URL:      server.URL,
				Username: "******",
				Password: "******",
			})

			err := client.SetVMResurrection("", "", 0, true)
			Expect(err).To(MatchError("unexpected response 418 I'm a teapot: something bad happened"))
		})

		It("returns an error when the body fails to read", func() {
			server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				w.WriteHeader(http.StatusTeapot)
				w.Write([]byte(""))
			}))

			client := bosh.NewClient(bosh.Config{
				URL:      server.URL,
				Username: "******",
				Password: "******",
			})

			bosh.SetBodyReader(func(io.Reader) ([]byte, error) {
				return nil, errors.New("failed to read")
			})

			err := client.SetVMResurrection("", "", 0, true)
			Expect(err).To(MatchError("failed to read"))
		})
	})
})