File: response_test.go

package info (click to toggle)
golang-github-hashicorp-go-azure-helpers 0.13.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 308 kB
  • sloc: makefile: 10
file content (65 lines) | stat: -rw-r--r-- 1,462 bytes parent folder | download | duplicates (2)
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
package response

import (
	"net/http"
	"testing"
)

func TestConflict_DroppedConnection(t *testing.T) {
	resp := http.Response{}
	if WasConflict(&resp) {
		t.Fatalf("wasConflict should return `false` for a dropped connection")
	}
}

func TestConflcit_StatusCodes(t *testing.T) {
	testCases := []struct {
		statusCode     int
		expectedResult bool
	}{
		{http.StatusOK, false},
		{http.StatusInternalServerError, false},
		{http.StatusNotFound, false},
		{http.StatusConflict, true},
	}

	for _, test := range testCases {
		resp := http.Response{
			StatusCode: test.statusCode,
		}
		result := WasConflict(&resp)
		if test.expectedResult != result {
			t.Fatalf("Expected '%+v' for status code '%d' - got '%+v'",
				test.expectedResult, test.statusCode, result)
		}
	}
}

func TestNotFound_DroppedConnection(t *testing.T) {
	resp := http.Response{}
	if WasNotFound(&resp) {
		t.Fatalf("wasNotFound should return `false` for a dropped connection")
	}
}

func TestNotFound_StatusCodes(t *testing.T) {
	testCases := []struct {
		statusCode     int
		expectedResult bool
	}{
		{http.StatusOK, false},
		{http.StatusInternalServerError, false},
		{http.StatusNotFound, true},
	}

	for _, test := range testCases {
		resp := http.Response{
			StatusCode: test.statusCode,
		}
		result := WasNotFound(&resp)
		if test.expectedResult != result {
			t.Fatalf("Expected '%+v' for status code '%d' - got '%+v'",
				test.expectedResult, test.statusCode, result)
		}
	}
}