File: errors_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 (61 lines) | stat: -rw-r--r-- 1,285 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
package httpclient_test

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

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

var _ = Describe("InvalidStatusError", func() {
	Describe("IsInvalidStatusError", func() {
		It("should check if value is InvalidStatusError", func() {
			err := InvalidStatusError{
				Expected: []int{200},
				Got:      409,
				Headers:  make(http.Header),
				Content:  "Error",
			}

			var _ error = err

			_, ok := IsInvalidStatusError(err)
			Expect(ok).To(BeTrue())
		})

		It("should check if pointer is InvalidStatusError", func() {
			err := &InvalidStatusError{
				Expected: []int{200},
				Got:      409,
				Headers:  make(http.Header),
				Content:  "Error",
			}

			var _ error = err

			_, ok := IsInvalidStatusError(err)
			Expect(ok).To(BeTrue())
		})
	})

	Describe("IsInvalidStatusCode", func() {
		It("should check if status code matches", func() {
			err := InvalidStatusError{
				Expected: []int{200},
				Got:      409,
				Headers:  make(http.Header),
				Content:  "Error",
			}

			var _ error = err

			Expect(IsInvalidStatusCode(err, 409)).To(BeTrue())
		})

		It("should return false if error is not valid", func() {
			Expect(IsInvalidStatusCode(fmt.Errorf("error"), 409)).To(BeFalse())
		})
	})
})