File: requestdata_test.go

package info (click to toggle)
golang-github-koofr-go-httpclient 0.0~git20190818.e0dc8fd-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 160 kB
  • sloc: makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,482 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package httpclient_test

import (
	. "github.com/koofr/go-httpclient"
	"net/http"
	"net/url"
	"strings"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("RequestData", func() {
	Describe("Copy", func() {
		It("should copy the request", func() {
			params := make(url.Values)
			params.Set("param", "value")

			headers := make(http.Header)
			headers.Set("X-Header", "value")

			reqValue := map[string]string{
				"key": "value",
			}

			respValue := map[string]string{}

			req := &RequestData{
				Method:          "GET",
				Path:            "/path",
				Params:          params,
				Headers:         headers,
				ReqEncoding:     EncodingJSON,
				ReqValue:        reqValue,
				ExpectedStatus:  []int{200},
				IgnoreRedirects: true,
				RespEncoding:    EncodingXML,
				RespValue:       &respValue,
				RespConsume:     true,
			}

			ok, reqCopy := req.Copy()
			Expect(ok).To(BeTrue())

			Expect(req).To(Equal(reqCopy))
			Expect(&req.Params == &reqCopy.Params).To(BeFalse())
			Expect(&req.Headers == &reqCopy.Headers).To(BeFalse())
			Expect(&req.ExpectedStatus == &reqCopy.ExpectedStatus).To(BeFalse())
		})
	})

	Describe("CanCopy", func() {
		It("should not copy request with reader", func() {
			req := &RequestData{
				Method:    "GET",
				Path:      "/path",
				ReqReader: strings.NewReader("data"),
			}

			canCopy := req.CanCopy()
			Expect(canCopy).To(BeFalse())

			ok, _ := req.Copy()
			Expect(ok).To(BeFalse())
		})
	})
})