Example #1
0
func sendRequest(opts *args.Options, req *http.Request, payload *[]byte) (string, error) {
	req.Header.Set("Content-Type", "application/json")

	// Print a curl representation of the request if verbose
	curl := args.CurlString(req, payload)
	if opts.Bool("verbose") {
		fmt.Printf("-- %s\n", curl)
	}

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		return "", errors.Wrap(err, "Client Error")
	}
	defer resp.Body.Close()

	// Read in the entire response
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "", errors.Wrap(err, "ReadAll Error")
	}
	return string(body), nil
}
Example #2
0
	Describe("Int()", func() {
		It("Should convert values to integers", func() {
			result := opts.Int("int")
			Expect(log.GetEntry()).To(Equal(""))
			Expect(result).To(Equal(1))
		})
		It("Should return default value if key doesn't exist", func() {
			result := opts.Int("none")
			Expect(log.GetEntry()).To(Equal(""))
			Expect(result).To(Equal(0))
		})

	})
	Describe("Bool()", func() {
		It("Should convert values to boolean", func() {
			result := opts.Bool("bool")
			Expect(log.GetEntry()).To(Equal(""))
			Expect(result).To(Equal(true))
		})
		It("Should return default value if key doesn't exist", func() {
			result := opts.Bool("none")
			Expect(result).To(Equal(false))
		})
	})
	Describe("String()", func() {
		It("Should return values as string", func() {
			result := opts.String("string")
			Expect(log.GetEntry()).To(Equal(""))
			Expect(result).To(Equal("one"))
		})
		It("Should return default value if key doesn't exist", func() {