| 1 | package jsonclientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src . bytes/" |
| 5 | "contextscip-go gomod github.com/golang/go/src . context/" |
| 6 | "errorsscip-go gomod github.com/golang/go/src . errors/" |
| 7 | "fmtscip-go gomod github.com/golang/go/src . fmt/" |
| 8 | "ioscip-go gomod github.com/golang/go/src . io/" |
| 9 | "net/httpscip-go gomod github.com/golang/go/src . `net/http`/" |
| 10 | "net/http/httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/" |
| 11 | "testingscip-go gomod github.com/golang/go/src . testing/" |
| 12 | |
| 13 | "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/" |
| 14 | "github.com/stretchr/testify/mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/" |
| 15 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/" |
| 16 | |
| 17 | "github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocksscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/" |
| 18 | ) |
| 19 | |
| 20 | // errorTransport is an HTTP client transport that always returns an error. |
| 21 | type errorTransportscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/errorTransport# struct { |
| 22 | errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/errorTransport#err. error |
| 23 | } |
| 24 | |
| 25 | // Compile-time interface compliance check. |
| 26 | var _ Clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client# = (*clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#)(nil) |
| 27 | |
| 28 | // RoundTrip implements the http.RoundTripper interface. |
| 29 | func (e *errorTransportscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/errorTransport#) RoundTripscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/errorTransport#RoundTrip().(req *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) (*httpscip-go gomod github.com/golang/go/src . `net/http`/.Responsescip-go gomod github.com/golang/go/src . `net/http`/Response#, error) { |
| 30 | return nil, e.errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/errorTransport#err. |
| 31 | } |
| 32 | |
| 33 | // TestError_Error tests the Error method of the Error type. |
| 34 | func TestError_Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestError_Error().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 35 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 36 | |
| 37 | tests := []struct { |
| 38 | name string |
| 39 | je Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error# |
| 40 | want string |
| 41 | }{ |
| 42 | { |
| 43 | name: "returns internal error message", |
| 44 | je: Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#{ |
| 45 | StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode.: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src . `net/http`/StatusBadRequest., |
| 46 | Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body.: `{"error": "bad request"}`, |
| 47 | errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err.: errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("internal error"), |
| 48 | }, |
| 49 | want: "internal error", |
| 50 | }, |
| 51 | { |
| 52 | name: "returns generic message when no internal error", |
| 53 | je: Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#{ |
| 54 | StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode.: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusInternalServerErrorscip-go gomod github.com/golang/go/src . `net/http`/StatusInternalServerError., |
| 55 | Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body.: "", |
| 56 | errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err.: nil, |
| 57 | }, |
| 58 | want: "unknown error (HTTP 500)", |
| 59 | }, |
| 60 | } |
| 61 | |
| 62 | for _, tt := range tests { |
| 63 | t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 64 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 65 | |
| 66 | got := tt.je.Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Error().() |
| 67 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.want, got, "Error.Error() mismatch") |
| 68 | }) |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // TestError_String tests the String method of the Error type. |
| 73 | func TestError_Stringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestError_String().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 74 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 75 | |
| 76 | tests := []struct { |
| 77 | name string |
| 78 | je Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error# |
| 79 | want string |
| 80 | }{ |
| 81 | { |
| 82 | name: "returns internal error when set", |
| 83 | je: Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#{ |
| 84 | StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode.: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusNotFoundscip-go gomod github.com/golang/go/src . `net/http`/StatusNotFound., |
| 85 | Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body.: `{"message": "not found"}`, |
| 86 | errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err.: errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("resource not found"), |
| 87 | }, |
| 88 | want: "resource not found", |
| 89 | }, |
| 90 | { |
| 91 | name: "returns generic message without internal error", |
| 92 | je: Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#{ |
| 93 | StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode.: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusUnauthorizedscip-go gomod github.com/golang/go/src . `net/http`/StatusUnauthorized., |
| 94 | Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body.: "", |
| 95 | errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err.: nil, |
| 96 | }, |
| 97 | want: "unknown error (HTTP 401)", |
| 98 | }, |
| 99 | { |
| 100 | name: "returns wrapped error message", |
| 101 | je: Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#{ |
| 102 | StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode.: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusForbiddenscip-go gomod github.com/golang/go/src . `net/http`/StatusForbidden., |
| 103 | Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body.: `{"error": "access denied"}`, |
| 104 | errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err.: fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("wrapped: %w", errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("base error")), |
| 105 | }, |
| 106 | want: "wrapped: base error", |
| 107 | }, |
| 108 | } |
| 109 | |
| 110 | for _, tt := range tests { |
| 111 | t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 112 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 113 | |
| 114 | got := tt.je.Stringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#String().() |
| 115 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.want, got, "Error.String() mismatch") |
| 116 | }) |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | // TestErrorBody tests the ErrorBody helper function. |
| 121 | func TestErrorBodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestErrorBody().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 122 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 123 | |
| 124 | tests := []struct { |
| 125 | name string |
| 126 | e error |
| 127 | want string |
| 128 | }{ |
| 129 | { |
| 130 | name: "extracts body from jsonclient.Error", |
| 131 | e: Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#{ |
| 132 | StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode.: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src . `net/http`/StatusBadRequest., |
| 133 | Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body.: `{"error": "validation failed"}`, |
| 134 | errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err.: errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("bad request"), |
| 135 | }, |
| 136 | want: `{"error": "validation failed"}`, |
| 137 | }, |
| 138 | { |
| 139 | name: "returns empty string for non-jsonclient.Error", |
| 140 | e: errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("some other error"), |
| 141 | want: "", |
| 142 | }, |
| 143 | { |
| 144 | name: "returns empty string for wrapped non-jsonclient.Error", |
| 145 | e: fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("wrapped: %w", errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("regular error")), |
| 146 | want: "", |
| 147 | }, |
| 148 | { |
| 149 | name: "extracts body from wrapped jsonclient.Error", |
| 150 | e: fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("wrapped: %w", Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#{ |
| 151 | StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode.: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusTeapotscip-go gomod github.com/golang/go/src . `net/http`/StatusTeapot., |
| 152 | Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body.: "I'm a teapot", |
| 153 | errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err.: errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("teapot error"), |
| 154 | }), |
| 155 | want: "I'm a teapot", |
| 156 | }, |
| 157 | { |
| 158 | name: "returns empty string for nil error", |
| 159 | e: nil, |
| 160 | want: "", |
| 161 | }, |
| 162 | } |
| 163 | |
| 164 | for _, tt := range tests { |
| 165 | t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 166 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 167 | |
| 168 | got := ErrorBodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ErrorBody().(tt.e) |
| 169 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.want, got, "ErrorBody() mismatch") |
| 170 | }) |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | // TestNewClient tests the NewClient constructor. |
| 175 | func TestNewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestNewClient().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 176 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 177 | |
| 178 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 179 | |
| 180 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NotNil().(t, client, "NewClient() should not return nil") |
| 181 | |
| 182 | // Verify headers are set correctly |
| 183 | headers := client.Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Headers.() |
| 184 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NotNil().(t, headers, "Headers() should not return nil") |
| 185 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType., headers.Getscip-go gomod github.com/golang/go/src . `net/http`/Header#Get().("Content-Type"), "Content-Type header mismatch") |
| 186 | } |
| 187 | |
| 188 | // TestNewWithHTTPClient tests the NewWithHTTPClient constructor. |
| 189 | func TestNewWithHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestNewWithHTTPClient().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 190 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 191 | |
| 192 | customHTTPClient := &httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#{ |
| 193 | Timeoutscip-go gomod github.com/golang/go/src . `net/http`/Client#Timeout.: 0, |
| 194 | } |
| 195 | |
| 196 | client := NewWithHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewWithHTTPClient().(customHTTPClient) |
| 197 | |
| 198 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NotNil().(t, client, "NewWithHTTPClient() should not return nil") |
| 199 | |
| 200 | // Verify headers are set correctly |
| 201 | headers := client.Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Headers.() |
| 202 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NotNil().(t, headers, "Headers() should not return nil") |
| 203 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType., headers.Getscip-go gomod github.com/golang/go/src . `net/http`/Header#Get().("Content-Type"), "Content-Type header mismatch") |
| 204 | } |
| 205 | |
| 206 | // TestClient_Get_Success tests successful GET requests. |
| 207 | func TestClient_Get_Successscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Get_Success().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 208 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 209 | |
| 210 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 211 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodGetscip-go gomod github.com/golang/go/src . `net/http`/MethodGet., r.Methodscip-go gomod github.com/golang/go/src . `net/http`/Request#Method., "HTTP method mismatch") |
| 212 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType., r.Headerscip-go gomod github.com/golang/go/src . `net/http`/Request#Header..Getscip-go gomod github.com/golang/go/src . `net/http`/Header#Get().("Content-Type"), "Content-Type header mismatch") |
| 213 | |
| 214 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 215 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 216 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"message": "success", "data": 123}`)) |
| 217 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 218 | })) |
| 219 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 220 | |
| 221 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 222 | |
| 223 | var response struct { |
| 224 | Message string `json:"message"` |
| 225 | Data int `json:"data"` |
| 226 | } |
| 227 | |
| 228 | err := client.Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Get.(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., &response) |
| 229 | |
| 230 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Get() should not return error") |
| 231 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "success", response.Message, "Response message mismatch") |
| 232 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, 123, response.Data, "Response data mismatch") |
| 233 | } |
| 234 | |
| 235 | // TestClient_Get_HTTPError tests GET requests that return HTTP error status codes. |
| 236 | func TestClient_Get_HTTPErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Get_HTTPError().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 237 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 238 | |
| 239 | tests := []struct { |
| 240 | name string |
| 241 | statusCode int |
| 242 | body string |
| 243 | wantErr bool |
| 244 | }{ |
| 245 | { |
| 246 | name: "bad request", |
| 247 | statusCode: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src . `net/http`/StatusBadRequest., |
| 248 | body: `{"error": "invalid request"}`, |
| 249 | wantErr: true, |
| 250 | }, |
| 251 | { |
| 252 | name: "unauthorized", |
| 253 | statusCode: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusUnauthorizedscip-go gomod github.com/golang/go/src . `net/http`/StatusUnauthorized., |
| 254 | body: `{"error": "authentication required"}`, |
| 255 | wantErr: true, |
| 256 | }, |
| 257 | { |
| 258 | name: "not found", |
| 259 | statusCode: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusNotFoundscip-go gomod github.com/golang/go/src . `net/http`/StatusNotFound., |
| 260 | body: `{"error": "resource not found"}`, |
| 261 | wantErr: true, |
| 262 | }, |
| 263 | { |
| 264 | name: "server error", |
| 265 | statusCode: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusInternalServerErrorscip-go gomod github.com/golang/go/src . `net/http`/StatusInternalServerError., |
| 266 | body: `{"error": "internal server error"}`, |
| 267 | wantErr: true, |
| 268 | }, |
| 269 | } |
| 270 | |
| 271 | for _, tt := range tests { |
| 272 | t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 273 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 274 | |
| 275 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 276 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 277 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(tt.statusCode) |
| 278 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(tt.body)) |
| 279 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 280 | })) |
| 281 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 282 | |
| 283 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 284 | |
| 285 | var response any |
| 286 | |
| 287 | err := client.Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Get.(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., &response) |
| 288 | |
| 289 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "Get() should return error for HTTP %d", tt.statusCode) |
| 290 | |
| 291 | var jsonErr Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error# |
| 292 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.ErrorAsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/ErrorAs().(t, err, &jsonErr, "Error should be jsonclient.Error") |
| 293 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.statusCode, jsonErr.StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode., "StatusCode mismatch") |
| 294 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.body, jsonErr.Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body., "Body mismatch") |
| 295 | }) |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | // TestClient_Get_InvalidJSON tests GET requests with invalid JSON responses. |
| 300 | func TestClient_Get_InvalidJSONscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Get_InvalidJSON().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 301 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 302 | |
| 303 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 304 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 305 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 306 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{invalid json`)) |
| 307 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 308 | })) |
| 309 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 310 | |
| 311 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 312 | |
| 313 | var response any |
| 314 | |
| 315 | err := client.Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Get.(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., &response) |
| 316 | |
| 317 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "Get() should return error for invalid JSON") |
| 318 | |
| 319 | var jsonErr Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error# |
| 320 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.ErrorAsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/ErrorAs().(t, err, &jsonErr, "Error should be jsonclient.Error") |
| 321 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK., jsonErr.StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode., "StatusCode should be 200") |
| 322 | } |
| 323 | |
| 324 | // TestClient_Get_NetworkError tests GET requests with network errors. |
| 325 | func TestClient_Get_NetworkErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Get_NetworkError().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 326 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 327 | |
| 328 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 329 | |
| 330 | var response any |
| 331 | |
| 332 | // Use an invalid URL to trigger a network error |
| 333 | err := client.Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Get.("http://[invalid-url", &response) |
| 334 | |
| 335 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "Get() should return error for invalid URL") |
| 336 | } |
| 337 | |
| 338 | // TestClient_Post_Success tests successful POST requests with struct body. |
| 339 | func TestClient_Post_Successscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Post_Success().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 340 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 341 | |
| 342 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 343 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodPostscip-go gomod github.com/golang/go/src . `net/http`/MethodPost., r.Methodscip-go gomod github.com/golang/go/src . `net/http`/Request#Method., "HTTP method mismatch") |
| 344 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType., r.Headerscip-go gomod github.com/golang/go/src . `net/http`/Request#Header..Getscip-go gomod github.com/golang/go/src . `net/http`/Header#Get().("Content-Type"), "Content-Type header mismatch") |
| 345 | |
| 346 | // Read and verify request body |
| 347 | body, err := ioscip-go gomod github.com/golang/go/src . io/.ReadAllscip-go gomod github.com/golang/go/src . io/ReadAll().(r.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body.) |
| 348 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to read request body") |
| 349 | |
| 350 | defer func() { _ = r.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 351 | |
| 352 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.JSONEqscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/JSONEq().(t, `{"name": "test", "value": 42}`, string(body), "Request body mismatch") |
| 353 | |
| 354 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 355 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusCreatedscip-go gomod github.com/golang/go/src . `net/http`/StatusCreated.) |
| 356 | _, err = w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"id": "123", "status": "created"}`)) |
| 357 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 358 | })) |
| 359 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 360 | |
| 361 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 362 | |
| 363 | request := struct { |
| 364 | Name string `json:"name"` |
| 365 | Value int `json:"value"` |
| 366 | }{ |
| 367 | Name: "test", |
| 368 | Value: 42, |
| 369 | } |
| 370 | |
| 371 | var response struct { |
| 372 | ID string `json:"id"` |
| 373 | Status string `json:"status"` |
| 374 | } |
| 375 | |
| 376 | err := client.Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Post.(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., request, &response) |
| 377 | |
| 378 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Post() should not return error") |
| 379 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "123", response.ID, "Response ID mismatch") |
| 380 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "created", response.Status, "Response status mismatch") |
| 381 | } |
| 382 | |
| 383 | // TestClient_Post_StringBody tests POST requests with string body. |
| 384 | func TestClient_Post_StringBodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Post_StringBody().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 385 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 386 | |
| 387 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 388 | body, err := ioscip-go gomod github.com/golang/go/src . io/.ReadAllscip-go gomod github.com/golang/go/src . io/ReadAll().(r.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body.) |
| 389 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to read request body") |
| 390 | |
| 391 | defer func() { _ = r.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 392 | |
| 393 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.JSONEqscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/JSONEq().(t, `{"custom": "json"}`, string(body), "Request body mismatch") |
| 394 | |
| 395 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 396 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 397 | _, err = w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"result": "ok"}`)) |
| 398 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 399 | })) |
| 400 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 401 | |
| 402 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 403 | |
| 404 | request := `{"custom": "json"}` |
| 405 | |
| 406 | var response struct { |
| 407 | Result string `json:"result"` |
| 408 | } |
| 409 | |
| 410 | err := client.Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Post.(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., request, &response) |
| 411 | |
| 412 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Post() should not return error") |
| 413 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "ok", response.Result, "Response result mismatch") |
| 414 | } |
| 415 | |
| 416 | // TestClient_Post_HTTPError tests POST requests that return HTTP error status codes. |
| 417 | func TestClient_Post_HTTPErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Post_HTTPError().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 418 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 419 | |
| 420 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 421 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 422 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusUnprocessableEntityscip-go gomod github.com/golang/go/src . `net/http`/StatusUnprocessableEntity.) |
| 423 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"errors": ["field required"]}`)) |
| 424 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 425 | })) |
| 426 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 427 | |
| 428 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 429 | |
| 430 | request := struct { |
| 431 | Name string `json:"name"` |
| 432 | }{ |
| 433 | Name: "", |
| 434 | } |
| 435 | |
| 436 | var response any |
| 437 | |
| 438 | err := client.Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Post.(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., request, &response) |
| 439 | |
| 440 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "Post() should return error for HTTP 422") |
| 441 | |
| 442 | var jsonErr Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error# |
| 443 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.ErrorAsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/ErrorAs().(t, err, &jsonErr, "Error should be jsonclient.Error") |
| 444 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusUnprocessableEntityscip-go gomod github.com/golang/go/src . `net/http`/StatusUnprocessableEntity., jsonErr.StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode., "StatusCode mismatch") |
| 445 | } |
| 446 | |
| 447 | // TestClient_Headers tests the Headers method. |
| 448 | func TestClient_Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Headers().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 449 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 450 | |
| 451 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 452 | |
| 453 | headers := client.Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Headers.() |
| 454 | |
| 455 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NotNil().(t, headers, "Headers() should not return nil") |
| 456 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType., headers.Getscip-go gomod github.com/golang/go/src . `net/http`/Header#Get().("Content-Type"), "Content-Type header mismatch") |
| 457 | |
| 458 | // Verify that modifying the returned headers affects future requests |
| 459 | headers.Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("X-Custom-Header", "custom-value") |
| 460 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "custom-value", client.Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Headers.().Getscip-go gomod github.com/golang/go/src . `net/http`/Header#Get().("X-Custom-Header"), "Custom header should be set") |
| 461 | } |
| 462 | |
| 463 | // TestClient_ErrorResponse_Success tests ErrorResponse with valid JSON error body. |
| 464 | func TestClient_ErrorResponse_Successscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_ErrorResponse_Success().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 465 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 466 | |
| 467 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 468 | |
| 469 | jsonErr := Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#{ |
| 470 | StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode.: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src . `net/http`/StatusBadRequest., |
| 471 | Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body.: `{"error": "validation failed", "field": "name"}`, |
| 472 | errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err.: errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("bad request"), |
| 473 | } |
| 474 | |
| 475 | var errorResponse struct { |
| 476 | Error string `json:"error"` |
| 477 | Field string `json:"field"` |
| 478 | } |
| 479 | |
| 480 | result := client.ErrorResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#ErrorResponse.(jsonErr, &errorResponse) |
| 481 | |
| 482 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/True().(t, result, "ErrorResponse() should return true") |
| 483 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "validation failed", errorResponse.Error, "Error field mismatch") |
| 484 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "name", errorResponse.Field, "Field field mismatch") |
| 485 | } |
| 486 | |
| 487 | // TestClient_ErrorResponse_InvalidJSON tests ErrorResponse with invalid JSON error body. |
| 488 | func TestClient_ErrorResponse_InvalidJSONscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_ErrorResponse_InvalidJSON().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 489 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 490 | |
| 491 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 492 | |
| 493 | jsonErr := Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#{ |
| 494 | StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode.: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src . `net/http`/StatusBadRequest., |
| 495 | Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body.: `{invalid json`, |
| 496 | errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err.: errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("bad request"), |
| 497 | } |
| 498 | |
| 499 | var errorResponse any |
| 500 | |
| 501 | result := client.ErrorResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#ErrorResponse.(jsonErr, &errorResponse) |
| 502 | |
| 503 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Falsescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/False().(t, result, "ErrorResponse() should return false for invalid JSON") |
| 504 | } |
| 505 | |
| 506 | // TestClient_ErrorResponse_NonJSONError tests ErrorResponse with non-jsonclient.Error. |
| 507 | func TestClient_ErrorResponse_NonJSONErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_ErrorResponse_NonJSONError().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 508 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 509 | |
| 510 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 511 | |
| 512 | regularErr := errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("regular error") |
| 513 | |
| 514 | var errorResponse any |
| 515 | |
| 516 | result := client.ErrorResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#ErrorResponse.(regularErr, &errorResponse) |
| 517 | |
| 518 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Falsescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/False().(t, result, "ErrorResponse() should return false for non-jsonclient.Error") |
| 519 | } |
| 520 | |
| 521 | // TestGet_Success tests the package-level Get function with a successful response. |
| 522 | func TestGet_Successscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestGet_Success().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 523 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 524 | |
| 525 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 526 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 527 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 528 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"status": "ok"}`)) |
| 529 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 530 | })) |
| 531 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 532 | |
| 533 | var response struct { |
| 534 | Status string `json:"status"` |
| 535 | } |
| 536 | |
| 537 | err := Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Get().(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., &response) |
| 538 | |
| 539 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Get() should not return error") |
| 540 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "ok", response.Status, "Response status mismatch") |
| 541 | } |
| 542 | |
| 543 | // TestGet_Error tests the package-level Get function with an error response. |
| 544 | func TestGet_Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestGet_Error().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 545 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 546 | |
| 547 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 548 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusNotFoundscip-go gomod github.com/golang/go/src . `net/http`/StatusNotFound.) |
| 549 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`not found`)) |
| 550 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 551 | })) |
| 552 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 553 | |
| 554 | var response any |
| 555 | |
| 556 | err := Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Get().(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., &response) |
| 557 | |
| 558 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "Get() should return error") |
| 559 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Contains().(t, err.Error(), fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("getting JSON from %q", server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL.), "Error should contain URL") |
| 560 | } |
| 561 | |
| 562 | // TestPost_Success tests the package-level Post function with a successful response. |
| 563 | func TestPost_Successscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestPost_Success().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 564 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 565 | |
| 566 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 567 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 568 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 569 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"received": true}`)) |
| 570 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 571 | })) |
| 572 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 573 | |
| 574 | request := struct { |
| 575 | Data string `json:"data"` |
| 576 | }{ |
| 577 | Data: "test", |
| 578 | } |
| 579 | |
| 580 | var response struct { |
| 581 | Received bool `json:"received"` |
| 582 | } |
| 583 | |
| 584 | err := Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Post().(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., request, &response) |
| 585 | |
| 586 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Post() should not return error") |
| 587 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/True().(t, response.Received, "Response received should be true") |
| 588 | } |
| 589 | |
| 590 | // TestPost_Error tests the package-level Post function with an error response. |
| 591 | func TestPost_Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestPost_Error().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 592 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 593 | |
| 594 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 595 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusInternalServerErrorscip-go gomod github.com/golang/go/src . `net/http`/StatusInternalServerError.) |
| 596 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`server error`)) |
| 597 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 598 | })) |
| 599 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 600 | |
| 601 | request := struct { |
| 602 | Data string `json:"data"` |
| 603 | }{ |
| 604 | Data: "test", |
| 605 | } |
| 606 | |
| 607 | var response any |
| 608 | |
| 609 | err := Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Post().(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., request, &response) |
| 610 | |
| 611 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "Post() should return error") |
| 612 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Contains().(t, err.Error(), fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("posting JSON to %q", server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL.), "Error should contain URL") |
| 613 | } |
| 614 | |
| 615 | // TestParseResponse_Success tests successful response parsing. |
| 616 | func TestParseResponse_Successscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestParseResponse_Success().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 617 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 618 | |
| 619 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 620 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 621 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 622 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"id": 1, "name": "test"}`)) |
| 623 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 624 | })) |
| 625 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 626 | |
| 627 | req, err := httpscip-go gomod github.com/golang/go/src . `net/http`/.NewRequestWithContextscip-go gomod github.com/golang/go/src . `net/http`/NewRequestWithContext().(contextscip-go gomod github.com/golang/go/src . context/.Backgroundscip-go gomod github.com/golang/go/src . context/Background().(), httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodGetscip-go gomod github.com/golang/go/src . `net/http`/MethodGet., server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., httpscip-go gomod github.com/golang/go/src . `net/http`/.NoBodyscip-go gomod github.com/golang/go/src . `net/http`/NoBody.) |
| 628 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Failed to create request") |
| 629 | |
| 630 | client := &httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#{} |
| 631 | resp, err := client.Doscip-go gomod github.com/golang/go/src . `net/http`/Client#Do().(req) |
| 632 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Failed to make request") |
| 633 | |
| 634 | defer func() { _ = resp.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 635 | |
| 636 | var result struct { |
| 637 | ID int `json:"id"` |
| 638 | Name string `json:"name"` |
| 639 | } |
| 640 | |
| 641 | err = parseResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/parseResponse().(resp, &result) |
| 642 | |
| 643 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "parseResponse() should not return error") |
| 644 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, 1, result.ID, "ID mismatch") |
| 645 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "test", result.Name, "Name mismatch") |
| 646 | } |
| 647 | |
| 648 | // TestParseResponse_HTTPError tests response parsing with HTTP error status. |
| 649 | func TestParseResponse_HTTPErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestParseResponse_HTTPError().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 650 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 651 | |
| 652 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 653 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src . `net/http`/StatusBadRequest.) |
| 654 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"error": "bad request"}`)) |
| 655 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 656 | })) |
| 657 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 658 | |
| 659 | req, err := httpscip-go gomod github.com/golang/go/src . `net/http`/.NewRequestWithContextscip-go gomod github.com/golang/go/src . `net/http`/NewRequestWithContext().(contextscip-go gomod github.com/golang/go/src . context/.Backgroundscip-go gomod github.com/golang/go/src . context/Background().(), httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodGetscip-go gomod github.com/golang/go/src . `net/http`/MethodGet., server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., httpscip-go gomod github.com/golang/go/src . `net/http`/.NoBodyscip-go gomod github.com/golang/go/src . `net/http`/NoBody.) |
| 660 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Failed to create request") |
| 661 | |
| 662 | client := &httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#{} |
| 663 | resp, err := client.Doscip-go gomod github.com/golang/go/src . `net/http`/Client#Do().(req) |
| 664 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Failed to make request") |
| 665 | |
| 666 | defer func() { _ = resp.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 667 | |
| 668 | var result any |
| 669 | |
| 670 | err = parseResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/parseResponse().(resp, &result) |
| 671 | |
| 672 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "parseResponse() should return error for HTTP 400") |
| 673 | |
| 674 | var jsonErr Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error# |
| 675 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.ErrorAsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/ErrorAs().(t, err, &jsonErr, "Error should be jsonclient.Error") |
| 676 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src . `net/http`/StatusBadRequest., jsonErr.StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode., "StatusCode mismatch") |
| 677 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.JSONEqscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/JSONEq().(t, `{"error": "bad request"}`, jsonErr.Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body., "Body mismatch") |
| 678 | } |
| 679 | |
| 680 | // TestParseResponse_InvalidJSON tests response parsing with invalid JSON. |
| 681 | func TestParseResponse_InvalidJSONscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestParseResponse_InvalidJSON().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 682 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 683 | |
| 684 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 685 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 686 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 687 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`not valid json`)) |
| 688 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 689 | })) |
| 690 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 691 | |
| 692 | req, err := httpscip-go gomod github.com/golang/go/src . `net/http`/.NewRequestWithContextscip-go gomod github.com/golang/go/src . `net/http`/NewRequestWithContext().(contextscip-go gomod github.com/golang/go/src . context/.Backgroundscip-go gomod github.com/golang/go/src . context/Background().(), httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodGetscip-go gomod github.com/golang/go/src . `net/http`/MethodGet., server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., httpscip-go gomod github.com/golang/go/src . `net/http`/.NoBodyscip-go gomod github.com/golang/go/src . `net/http`/NoBody.) |
| 693 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Failed to create request") |
| 694 | |
| 695 | client := &httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#{} |
| 696 | resp, err := client.Doscip-go gomod github.com/golang/go/src . `net/http`/Client#Do().(req) |
| 697 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Failed to make request") |
| 698 | |
| 699 | defer func() { _ = resp.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 700 | |
| 701 | var result any |
| 702 | |
| 703 | err = parseResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/parseResponse().(resp, &result) |
| 704 | |
| 705 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "parseResponse() should return error for invalid JSON") |
| 706 | |
| 707 | var jsonErr Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error# |
| 708 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.ErrorAsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/ErrorAs().(t, err, &jsonErr, "Error should be jsonclient.Error") |
| 709 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK., jsonErr.StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode., "StatusCode should be 200") |
| 710 | } |
| 711 | |
| 712 | // TestParseResponse_EmptyBody tests response parsing with empty body. |
| 713 | func TestParseResponse_EmptyBodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestParseResponse_EmptyBody().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 714 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 715 | |
| 716 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 717 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 718 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 719 | })) |
| 720 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 721 | |
| 722 | req, err := httpscip-go gomod github.com/golang/go/src . `net/http`/.NewRequestWithContextscip-go gomod github.com/golang/go/src . `net/http`/NewRequestWithContext().(contextscip-go gomod github.com/golang/go/src . context/.Backgroundscip-go gomod github.com/golang/go/src . context/Background().(), httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodGetscip-go gomod github.com/golang/go/src . `net/http`/MethodGet., server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., httpscip-go gomod github.com/golang/go/src . `net/http`/.NoBodyscip-go gomod github.com/golang/go/src . `net/http`/NoBody.) |
| 723 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Failed to create request") |
| 724 | |
| 725 | client := &httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#{} |
| 726 | resp, err := client.Doscip-go gomod github.com/golang/go/src . `net/http`/Client#Do().(req) |
| 727 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Failed to make request") |
| 728 | |
| 729 | defer func() { _ = resp.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 730 | |
| 731 | var result any |
| 732 | |
| 733 | err = parseResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/parseResponse().(resp, &result) |
| 734 | |
| 735 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "parseResponse() should return error for empty body") |
| 736 | } |
| 737 | |
| 738 | // Mock Client Interface Tests |
| 739 | |
| 740 | // TestMockClient_Get tests mocking the Client interface Get method. |
| 741 | func TestMockClient_Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestMockClient_Get().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 742 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 743 | |
| 744 | mockClient := mocksscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/.NewMockClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/NewMockClient().(t) |
| 745 | |
| 746 | expectedResponse := struct { |
| 747 | Data string `json:"data"` |
| 748 | }{ |
| 749 | Data: "mocked", |
| 750 | } |
| 751 | |
| 752 | mockClient.EXPECTscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient#EXPECT().().Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient_Expecter#Get().("http://example.com", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.).RunAndReturnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient_Get_Call#RunAndReturn().(func(url string, response any) error { |
| 753 | // Simulate unmarshaling into the response |
| 754 | respPtr, ok := response.(*struct { |
| 755 | Data string `json:"data"` |
| 756 | }) |
| 757 | if ok { |
| 758 | respPtr.Data = "mocked" |
| 759 | } |
| 760 | |
| 761 | return nil |
| 762 | }) |
| 763 | |
| 764 | var response struct { |
| 765 | Data string `json:"data"` |
| 766 | } |
| 767 | |
| 768 | err := mockClient.Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient#Get().("http://example.com", &response) |
| 769 | |
| 770 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Get() should not return error") |
| 771 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, expectedResponse.Data, response.Data, "Response data mismatch") |
| 772 | } |
| 773 | |
| 774 | // TestMockClient_Get_Error tests mocking the Client interface Get method with error. |
| 775 | func TestMockClient_Get_Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestMockClient_Get_Error().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 776 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 777 | |
| 778 | mockClient := mocksscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/.NewMockClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/NewMockClient().(t) |
| 779 | |
| 780 | expectedErr := errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("mocked error") |
| 781 | |
| 782 | mockClient.EXPECTscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient#EXPECT().().Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient_Expecter#Get().("http://example.com", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.).Returnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient_Get_Call#Return().(expectedErr) |
| 783 | |
| 784 | var response any |
| 785 | |
| 786 | err := mockClient.Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient#Get().("http://example.com", &response) |
| 787 | |
| 788 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "Get() should return error") |
| 789 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, expectedErr, err, "Error mismatch") |
| 790 | } |
| 791 | |
| 792 | // TestMockClient_Post tests mocking the Client interface Post method. |
| 793 | func TestMockClient_Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestMockClient_Post().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 794 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 795 | |
| 796 | mockClient := mocksscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/.NewMockClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/NewMockClient().(t) |
| 797 | |
| 798 | expectedResponse := struct { |
| 799 | ID string `json:"id"` |
| 800 | }{ |
| 801 | ID: "123", |
| 802 | } |
| 803 | |
| 804 | mockClient.EXPECTscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient#EXPECT().().Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient_Expecter#Post().("http://example.com", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything., mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.).RunAndReturnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient_Post_Call#RunAndReturn().( |
| 805 | func(url string, request, response any) error { |
| 806 | // Simulate unmarshaling into the response |
| 807 | respPtr, ok := response.(*struct { |
| 808 | ID string `json:"id"` |
| 809 | }) |
| 810 | if ok { |
| 811 | respPtr.ID = "123" |
| 812 | } |
| 813 | |
| 814 | return nil |
| 815 | }, |
| 816 | ) |
| 817 | |
| 818 | request := struct { |
| 819 | Name string `json:"name"` |
| 820 | }{ |
| 821 | Name: "test", |
| 822 | } |
| 823 | |
| 824 | var response struct { |
| 825 | ID string `json:"id"` |
| 826 | } |
| 827 | |
| 828 | err := mockClient.Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient#Post().("http://example.com", request, &response) |
| 829 | |
| 830 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Post() should not return error") |
| 831 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, expectedResponse.ID, response.ID, "Response ID mismatch") |
| 832 | } |
| 833 | |
| 834 | // TestMockClient_Post_Error tests mocking the Client interface Post method with error. |
| 835 | func TestMockClient_Post_Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestMockClient_Post_Error().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 836 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 837 | |
| 838 | mockClient := mocksscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/.NewMockClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/NewMockClient().(t) |
| 839 | |
| 840 | expectedErr := errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("post failed") |
| 841 | |
| 842 | mockClient.EXPECTscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient#EXPECT().().Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient_Expecter#Post().("http://example.com", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything., mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.).Returnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient_Post_Call#Return().(expectedErr) |
| 843 | |
| 844 | request := struct { |
| 845 | Name string `json:"name"` |
| 846 | }{ |
| 847 | Name: "test", |
| 848 | } |
| 849 | |
| 850 | var response any |
| 851 | |
| 852 | err := mockClient.Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient#Post().("http://example.com", request, &response) |
| 853 | |
| 854 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "Post() should return error") |
| 855 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, expectedErr, err, "Error mismatch") |
| 856 | } |
| 857 | |
| 858 | // TestMockClient_Headers tests mocking the Client interface Headers method. |
| 859 | func TestMockClient_Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestMockClient_Headers().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 860 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 861 | |
| 862 | mockClient := mocksscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/.NewMockClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/NewMockClient().(t) |
| 863 | |
| 864 | expectedHeaders := httpscip-go gomod github.com/golang/go/src . `net/http`/.Headerscip-go gomod github.com/golang/go/src . `net/http`/Header#{ |
| 865 | "Content-Type": []string{ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.}, |
| 866 | "X-Custom": []string{"value"}, |
| 867 | } |
| 868 | |
| 869 | mockClient.EXPECTscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient#EXPECT().().Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient_Expecter#Headers().().Returnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient_Headers_Call#Return().(expectedHeaders) |
| 870 | |
| 871 | headers := mockClient.Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient#Headers().() |
| 872 | |
| 873 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType., headers.Getscip-go gomod github.com/golang/go/src . `net/http`/Header#Get().("Content-Type"), "Content-Type header mismatch") |
| 874 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "value", headers.Getscip-go gomod github.com/golang/go/src . `net/http`/Header#Get().("X-Custom"), "X-Custom header mismatch") |
| 875 | } |
| 876 | |
| 877 | // TestMockClient_ErrorResponse tests mocking the Client interface ErrorResponse method. |
| 878 | func TestMockClient_ErrorResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestMockClient_ErrorResponse().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 879 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 880 | |
| 881 | mockClient := mocksscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/.NewMockClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/NewMockClient().(t) |
| 882 | |
| 883 | testErr := Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#{ |
| 884 | StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode.: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src . `net/http`/StatusBadRequest., |
| 885 | Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body.: `{"error": "validation failed"}`, |
| 886 | errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err.: errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("bad request"), |
| 887 | } |
| 888 | |
| 889 | expectedResponse := struct { |
| 890 | Error string `json:"error"` |
| 891 | }{ |
| 892 | Error: "validation failed", |
| 893 | } |
| 894 | |
| 895 | mockClient.EXPECTscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient#EXPECT().().ErrorResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient_Expecter#ErrorResponse().(testErr, mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.).RunAndReturnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient_ErrorResponse_Call#RunAndReturn().( |
| 896 | func(err error, response any) bool { |
| 897 | respPtr, ok := response.(*struct { |
| 898 | Error string `json:"error"` |
| 899 | }) |
| 900 | if ok { |
| 901 | respPtr.Error = "validation failed" |
| 902 | } |
| 903 | |
| 904 | return true |
| 905 | }, |
| 906 | ) |
| 907 | |
| 908 | var response struct { |
| 909 | Error string `json:"error"` |
| 910 | } |
| 911 | |
| 912 | result := mockClient.ErrorResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient#ErrorResponse().(testErr, &response) |
| 913 | |
| 914 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/True().(t, result, "ErrorResponse() should return true") |
| 915 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, expectedResponse.Error, response.Error, "Response error mismatch") |
| 916 | } |
| 917 | |
| 918 | // TestMockClient_ErrorResponse_False tests ErrorResponse returning false. |
| 919 | func TestMockClient_ErrorResponse_Falsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestMockClient_ErrorResponse_False().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 920 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 921 | |
| 922 | mockClient := mocksscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/.NewMockClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/NewMockClient().(t) |
| 923 | |
| 924 | regularErr := errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("regular error") |
| 925 | |
| 926 | mockClient.EXPECTscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient#EXPECT().().ErrorResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient_Expecter#ErrorResponse().(regularErr, mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.).Returnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient_ErrorResponse_Call#Return().(false) |
| 927 | |
| 928 | var response any |
| 929 | |
| 930 | result := mockClient.ErrorResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient/mocks`/MockClient#ErrorResponse().(regularErr, &response) |
| 931 | |
| 932 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Falsescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/False().(t, result, "ErrorResponse() should return false") |
| 933 | } |
| 934 | |
| 935 | // Edge Case Tests |
| 936 | |
| 937 | // TestClient_Get_EmptyResponse tests GET with empty but valid JSON response. |
| 938 | func TestClient_Get_EmptyResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Get_EmptyResponse().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 939 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 940 | |
| 941 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 942 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 943 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 944 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{}`)) |
| 945 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 946 | })) |
| 947 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 948 | |
| 949 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 950 | |
| 951 | var response struct { |
| 952 | Optional string `json:"optional"` |
| 953 | } |
| 954 | |
| 955 | err := client.Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Get.(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., &response) |
| 956 | |
| 957 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Get() should not return error") |
| 958 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Emptyscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Empty().(t, response.Optional, "Optional field should be empty") |
| 959 | } |
| 960 | |
| 961 | // TestClient_Post_EmptyRequest tests POST with empty struct request. |
| 962 | func TestClient_Post_EmptyRequestscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Post_EmptyRequest().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 963 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 964 | |
| 965 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 966 | body, err := ioscip-go gomod github.com/golang/go/src . io/.ReadAllscip-go gomod github.com/golang/go/src . io/ReadAll().(r.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body.) |
| 967 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to read request body") |
| 968 | |
| 969 | defer func() { _ = r.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 970 | |
| 971 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.JSONEqscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/JSONEq().(t, `{}`, string(body), "Request body should be empty JSON object") |
| 972 | |
| 973 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 974 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 975 | _, err = w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"status": "ok"}`)) |
| 976 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 977 | })) |
| 978 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 979 | |
| 980 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 981 | |
| 982 | request := struct{}{} |
| 983 | |
| 984 | var response struct { |
| 985 | Status string `json:"status"` |
| 986 | } |
| 987 | |
| 988 | err := client.Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Post.(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., request, &response) |
| 989 | |
| 990 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Post() should not return error") |
| 991 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "ok", response.Status, "Response status mismatch") |
| 992 | } |
| 993 | |
| 994 | // TestClient_ErrorResponse_NilError tests ErrorResponse with nil error. |
| 995 | func TestClient_ErrorResponse_NilErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_ErrorResponse_NilError().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 996 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 997 | |
| 998 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 999 | |
| 1000 | var response any |
| 1001 | |
| 1002 | result := client.ErrorResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#ErrorResponse.(nil, &response) |
| 1003 | |
| 1004 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Falsescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/False().(t, result, "ErrorResponse() should return false for nil error") |
| 1005 | } |
| 1006 | |
| 1007 | // TestDefaultClient_NotNil tests that DefaultClient is not nil. |
| 1008 | func TestDefaultClient_NotNilscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestDefaultClient_NotNil().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1009 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1010 | |
| 1011 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NotNil().(t, DefaultClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/DefaultClient., "DefaultClient should not be nil") |
| 1012 | } |
| 1013 | |
| 1014 | // TestContentType_Constant tests the ContentType constant. |
| 1015 | func TestContentType_Constantscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestContentType_Constant().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1016 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1017 | |
| 1018 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "application/json", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType., "ContentType constant mismatch") |
| 1019 | } |
| 1020 | |
| 1021 | // TestHTTPClientErrorThreshold_Constant tests the HTTPClientErrorThreshold constant. |
| 1022 | func TestHTTPClientErrorThreshold_Constantscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestHTTPClientErrorThreshold_Constant().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1023 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1024 | |
| 1025 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, 400, HTTPClientErrorThresholdscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/HTTPClientErrorThreshold., "HTTPClientErrorThreshold constant mismatch") |
| 1026 | } |
| 1027 | |
| 1028 | // TestErrUnexpectedStatus tests the ErrUnexpectedStatus error. |
| 1029 | func TestErrUnexpectedStatusscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestErrUnexpectedStatus().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1030 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1031 | |
| 1032 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, ErrUnexpectedStatusscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ErrUnexpectedStatus., "ErrUnexpectedStatus should not be nil") |
| 1033 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "got unexpected HTTP status", ErrUnexpectedStatusscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ErrUnexpectedStatus..Error(), "ErrUnexpectedStatus message mismatch") |
| 1034 | |
| 1035 | // Verify it can be used with errors.Is |
| 1036 | wrappedErr := fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("wrapped: %w", ErrUnexpectedStatusscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ErrUnexpectedStatus.) |
| 1037 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.ErrorIsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/ErrorIs().(t, wrappedErr, ErrUnexpectedStatusscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ErrUnexpectedStatus., "ErrUnexpectedStatus should be detectable with errors.Is") |
| 1038 | } |
| 1039 | |
| 1040 | // TestClient_Post_MarshalError tests JSON marshaling failure with unmarshalable types. |
| 1041 | func TestClient_Post_MarshalErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Post_MarshalError().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1042 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1043 | |
| 1044 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 1045 | |
| 1046 | // Channel cannot be marshaled to JSON |
| 1047 | request := struct { |
| 1048 | Data chan int `json:"data"` |
| 1049 | }{ |
| 1050 | Data: make(chan int), |
| 1051 | } |
| 1052 | |
| 1053 | var response any |
| 1054 | |
| 1055 | err := client.Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Post.("http://example.com", request, &response) |
| 1056 | |
| 1057 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "Post() should return error for unmarshalable type") |
| 1058 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Contains().(t, err.Error(), "marshaling request to JSON", "Error should mention JSON marshaling") |
| 1059 | } |
| 1060 | |
| 1061 | // TestClient_Get_CustomHeaders verifies custom headers are actually sent in HTTP requests. |
| 1062 | func TestClient_Get_CustomHeadersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Get_CustomHeaders().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1063 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1064 | |
| 1065 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 1066 | // Verify custom header is received |
| 1067 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "custom-value", r.Headerscip-go gomod github.com/golang/go/src . `net/http`/Request#Header..Getscip-go gomod github.com/golang/go/src . `net/http`/Header#Get().("X-Custom-Header"), "Custom header mismatch") |
| 1068 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType., r.Headerscip-go gomod github.com/golang/go/src . `net/http`/Request#Header..Getscip-go gomod github.com/golang/go/src . `net/http`/Header#Get().("Content-Type"), "Content-Type header mismatch") |
| 1069 | |
| 1070 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 1071 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 1072 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"status": "ok"}`)) |
| 1073 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 1074 | })) |
| 1075 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 1076 | |
| 1077 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 1078 | client.Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Headers.().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("X-Custom-Header", "custom-value") |
| 1079 | |
| 1080 | var response struct { |
| 1081 | Status string `json:"status"` |
| 1082 | } |
| 1083 | |
| 1084 | err := client.Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Get.(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., &response) |
| 1085 | |
| 1086 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Get() should not return error") |
| 1087 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "ok", response.Status, "Response status mismatch") |
| 1088 | } |
| 1089 | |
| 1090 | // TestClient_Get_DoError tests httpClient.Do() errors. |
| 1091 | func TestClient_Get_DoErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Get_DoError().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1092 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1093 | |
| 1094 | expectedErr := errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("mock HTTP error") |
| 1095 | httpClient := &httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#{ |
| 1096 | Transportscip-go gomod github.com/golang/go/src . `net/http`/Client#Transport.: &errorTransportscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/errorTransport#{errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/errorTransport#err.: expectedErr}, |
| 1097 | } |
| 1098 | client := NewWithHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewWithHTTPClient().(httpClient) |
| 1099 | |
| 1100 | var response any |
| 1101 | |
| 1102 | err := client.Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Get.("http://example.com", &response) |
| 1103 | |
| 1104 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "Get() should return error for Do() failure") |
| 1105 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Contains().(t, err.Error(), "executing GET request", "Error should mention executing GET request") |
| 1106 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.ErrorIsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/ErrorIs().(t, err, expectedErr, "Error should wrap the original HTTP error") |
| 1107 | } |
| 1108 | |
| 1109 | // TestClient_Post_DoError tests POST httpClient.Do() errors. |
| 1110 | func TestClient_Post_DoErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Post_DoError().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1111 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1112 | |
| 1113 | expectedErr := errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("mock POST error") |
| 1114 | httpClient := &httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#{ |
| 1115 | Transportscip-go gomod github.com/golang/go/src . `net/http`/Client#Transport.: &errorTransportscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/errorTransport#{errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/errorTransport#err.: expectedErr}, |
| 1116 | } |
| 1117 | client := NewWithHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewWithHTTPClient().(httpClient) |
| 1118 | |
| 1119 | request := struct { |
| 1120 | Name string `json:"name"` |
| 1121 | }{ |
| 1122 | Name: "test", |
| 1123 | } |
| 1124 | |
| 1125 | var response any |
| 1126 | |
| 1127 | err := client.Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Post.("http://example.com", request, &response) |
| 1128 | |
| 1129 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "Post() should return error for Do() failure") |
| 1130 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Contains().(t, err.Error(), "sending POST request", "Error should mention sending POST request") |
| 1131 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.ErrorIsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/ErrorIs().(t, err, expectedErr, "Error should wrap the original HTTP error") |
| 1132 | } |
| 1133 | |
| 1134 | // TestParseResponse_StatusCodeBoundary verifies 399 = success, 400 = error. |
| 1135 | func TestParseResponse_StatusCodeBoundaryscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestParseResponse_StatusCodeBoundary().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1136 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1137 | |
| 1138 | tests := []struct { |
| 1139 | name string |
| 1140 | statusCode int |
| 1141 | wantErr bool |
| 1142 | }{ |
| 1143 | { |
| 1144 | name: "status 399 is success", |
| 1145 | statusCode: 399, |
| 1146 | wantErr: false, |
| 1147 | }, |
| 1148 | { |
| 1149 | name: "status 400 is error", |
| 1150 | statusCode: 400, |
| 1151 | wantErr: true, |
| 1152 | }, |
| 1153 | } |
| 1154 | |
| 1155 | for _, tt := range tests { |
| 1156 | t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1157 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1158 | |
| 1159 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 1160 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 1161 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(tt.statusCode) |
| 1162 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"data": "test"}`)) |
| 1163 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 1164 | })) |
| 1165 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 1166 | |
| 1167 | req, err := httpscip-go gomod github.com/golang/go/src . `net/http`/.NewRequestWithContextscip-go gomod github.com/golang/go/src . `net/http`/NewRequestWithContext().(contextscip-go gomod github.com/golang/go/src . context/.Backgroundscip-go gomod github.com/golang/go/src . context/Background().(), httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodGetscip-go gomod github.com/golang/go/src . `net/http`/MethodGet., server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., httpscip-go gomod github.com/golang/go/src . `net/http`/.NoBodyscip-go gomod github.com/golang/go/src . `net/http`/NoBody.) |
| 1168 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Failed to create request") |
| 1169 | |
| 1170 | client := &httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#{} |
| 1171 | resp, err := client.Doscip-go gomod github.com/golang/go/src . `net/http`/Client#Do().(req) |
| 1172 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Failed to make request") |
| 1173 | |
| 1174 | defer func() { _ = resp.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 1175 | |
| 1176 | var result struct { |
| 1177 | Data string `json:"data"` |
| 1178 | } |
| 1179 | |
| 1180 | err = parseResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/parseResponse().(resp, &result) |
| 1181 | |
| 1182 | if tt.wantErr { |
| 1183 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "parseResponse() should return error for HTTP %d", tt.statusCode) |
| 1184 | |
| 1185 | var jsonErr Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error# |
| 1186 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.ErrorAsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/ErrorAs().(t, err, &jsonErr, "Error should be jsonclient.Error") |
| 1187 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.statusCode, jsonErr.StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode., "StatusCode mismatch") |
| 1188 | } else { |
| 1189 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "parseResponse() should not return error for HTTP %d", tt.statusCode) |
| 1190 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "test", result.Data, "Data mismatch") |
| 1191 | } |
| 1192 | }) |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | // TestClient_Get_InvalidURL tests request creation error with malformed URL. |
| 1197 | func TestClient_Get_InvalidURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Get_InvalidURL().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1198 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1199 | |
| 1200 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 1201 | |
| 1202 | var response any |
| 1203 | |
| 1204 | // Use an invalid URL format to trigger request creation error |
| 1205 | err := client.Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Get.("://invalid-url", &response) |
| 1206 | |
| 1207 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "Get() should return error for invalid URL") |
| 1208 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Contains().(t, err.Error(), "creating GET request", "Error should mention creating GET request") |
| 1209 | } |
| 1210 | |
| 1211 | // TestClient_Post_InvalidURL tests POST request creation error. |
| 1212 | func TestClient_Post_InvalidURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Post_InvalidURL().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1213 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1214 | |
| 1215 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 1216 | |
| 1217 | request := struct { |
| 1218 | Name string `json:"name"` |
| 1219 | }{ |
| 1220 | Name: "test", |
| 1221 | } |
| 1222 | |
| 1223 | var response any |
| 1224 | |
| 1225 | // Use an invalid URL format to trigger request creation error |
| 1226 | err := client.Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Post.("://invalid-url", request, &response) |
| 1227 | |
| 1228 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "Post() should return error for invalid URL") |
| 1229 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Contains().(t, err.Error(), "creating POST request", "Error should mention creating POST request") |
| 1230 | } |
| 1231 | |
| 1232 | // TestParseResponse_NonJSONErrorBody tests HTML error pages (502 Bad Gateway). |
| 1233 | func TestParseResponse_NonJSONErrorBodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestParseResponse_NonJSONErrorBody().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1234 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1235 | |
| 1236 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 1237 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusBadGatewayscip-go gomod github.com/golang/go/src . `net/http`/StatusBadGateway.) |
| 1238 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`<html><body>502 Bad Gateway</body></html>`)) |
| 1239 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 1240 | })) |
| 1241 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 1242 | |
| 1243 | req, err := httpscip-go gomod github.com/golang/go/src . `net/http`/.NewRequestWithContextscip-go gomod github.com/golang/go/src . `net/http`/NewRequestWithContext().(contextscip-go gomod github.com/golang/go/src . context/.Backgroundscip-go gomod github.com/golang/go/src . context/Background().(), httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodGetscip-go gomod github.com/golang/go/src . `net/http`/MethodGet., server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., httpscip-go gomod github.com/golang/go/src . `net/http`/.NoBodyscip-go gomod github.com/golang/go/src . `net/http`/NoBody.) |
| 1244 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Failed to create request") |
| 1245 | |
| 1246 | client := &httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#{} |
| 1247 | resp, err := client.Doscip-go gomod github.com/golang/go/src . `net/http`/Client#Do().(req) |
| 1248 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Failed to make request") |
| 1249 | |
| 1250 | defer func() { _ = resp.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 1251 | |
| 1252 | var result any |
| 1253 | |
| 1254 | err = parseResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/parseResponse().(resp, &result) |
| 1255 | |
| 1256 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "parseResponse() should return error for HTTP 502") |
| 1257 | |
| 1258 | var jsonErr Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error# |
| 1259 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.ErrorAsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/ErrorAs().(t, err, &jsonErr, "Error should be jsonclient.Error") |
| 1260 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusBadGatewayscip-go gomod github.com/golang/go/src . `net/http`/StatusBadGateway., jsonErr.StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode., "StatusCode mismatch") |
| 1261 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Contains().(t, jsonErr.Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body., "502 Bad Gateway", "Body should contain HTML error message") |
| 1262 | } |
| 1263 | |
| 1264 | // TestClient_Post_EmptyStringBody tests empty string POST body. |
| 1265 | func TestClient_Post_EmptyStringBodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Post_EmptyStringBody().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1266 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1267 | |
| 1268 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 1269 | body, err := ioscip-go gomod github.com/golang/go/src . io/.ReadAllscip-go gomod github.com/golang/go/src . io/ReadAll().(r.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body.) |
| 1270 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to read request body") |
| 1271 | |
| 1272 | defer func() { _ = r.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 1273 | |
| 1274 | // Empty string body should be empty |
| 1275 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Emptyscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Empty().(t, string(body), "Request body should be empty for empty string") |
| 1276 | |
| 1277 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 1278 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 1279 | _, err = w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"result": "ok"}`)) |
| 1280 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 1281 | })) |
| 1282 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 1283 | |
| 1284 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 1285 | |
| 1286 | request := "" |
| 1287 | |
| 1288 | var response struct { |
| 1289 | Result string `json:"result"` |
| 1290 | } |
| 1291 | |
| 1292 | err := client.Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Post.(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., request, &response) |
| 1293 | |
| 1294 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Post() should not return error for empty string body") |
| 1295 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "ok", response.Result, "Response result mismatch") |
| 1296 | } |
| 1297 | |
| 1298 | // TestClient_InterfaceCompliance verifies compile-time interface compliance. |
| 1299 | func TestClient_InterfaceCompliancescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_InterfaceCompliance().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1300 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1301 | |
| 1302 | // This is a compile-time check - if it compiles, the test passes |
| 1303 | var _ Clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client# = (*clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#)(nil) |
| 1304 | |
| 1305 | // Also verify that NewClient returns the interface type |
| 1306 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 1307 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NotNil().(t, client, "NewClient() should return a non-nil Client") |
| 1308 | |
| 1309 | // Verify all interface methods are accessible |
| 1310 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NotNil().(t, client.Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Headers.(), "Headers() should be accessible") |
| 1311 | } |
| 1312 | |
| 1313 | // TestClient_MultipleHeaderValues tests only first header value is used. |
| 1314 | func TestClient_MultipleHeaderValuesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_MultipleHeaderValues().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1315 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1316 | |
| 1317 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 1318 | // The client should only send the first value |
| 1319 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "first-value", r.Headerscip-go gomod github.com/golang/go/src . `net/http`/Request#Header..Getscip-go gomod github.com/golang/go/src . `net/http`/Header#Get().("X-Multi-Header"), "Only first header value should be used") |
| 1320 | |
| 1321 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 1322 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 1323 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"status": "ok"}`)) |
| 1324 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 1325 | })) |
| 1326 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 1327 | |
| 1328 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 1329 | |
| 1330 | // Set multiple values for the same header |
| 1331 | client.Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Headers.()["X-Multi-Header"] = []string{"first-value", "second-value", "third-value"} |
| 1332 | |
| 1333 | var response struct { |
| 1334 | Status string `json:"status"` |
| 1335 | } |
| 1336 | |
| 1337 | err := client.Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Get.(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., &response) |
| 1338 | |
| 1339 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Get() should not return error") |
| 1340 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "ok", response.Status, "Response status mismatch") |
| 1341 | } |
| 1342 | |
| 1343 | // TestClient_Post_CustomHeaders verifies custom headers are sent in POST requests. |
| 1344 | func TestClient_Post_CustomHeadersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Post_CustomHeaders().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1345 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1346 | |
| 1347 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 1348 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodPostscip-go gomod github.com/golang/go/src . `net/http`/MethodPost., r.Methodscip-go gomod github.com/golang/go/src . `net/http`/Request#Method., "HTTP method mismatch") |
| 1349 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "custom-value", r.Headerscip-go gomod github.com/golang/go/src . `net/http`/Request#Header..Getscip-go gomod github.com/golang/go/src . `net/http`/Header#Get().("X-Custom-Header"), "Custom header mismatch") |
| 1350 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType., r.Headerscip-go gomod github.com/golang/go/src . `net/http`/Request#Header..Getscip-go gomod github.com/golang/go/src . `net/http`/Header#Get().("Content-Type"), "Content-Type header mismatch") |
| 1351 | |
| 1352 | body, err := ioscip-go gomod github.com/golang/go/src . io/.ReadAllscip-go gomod github.com/golang/go/src . io/ReadAll().(r.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body.) |
| 1353 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to read request body") |
| 1354 | |
| 1355 | defer func() { _ = r.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 1356 | |
| 1357 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.JSONEqscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/JSONEq().(t, `{"name": "test"}`, string(body), "Request body mismatch") |
| 1358 | |
| 1359 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 1360 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 1361 | _, err = w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"result": "ok"}`)) |
| 1362 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 1363 | })) |
| 1364 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 1365 | |
| 1366 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 1367 | client.Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Headers.().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("X-Custom-Header", "custom-value") |
| 1368 | |
| 1369 | request := struct { |
| 1370 | Name string `json:"name"` |
| 1371 | }{ |
| 1372 | Name: "test", |
| 1373 | } |
| 1374 | |
| 1375 | var response struct { |
| 1376 | Result string `json:"result"` |
| 1377 | } |
| 1378 | |
| 1379 | err := client.Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Post.(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., request, &response) |
| 1380 | |
| 1381 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Post() should not return error") |
| 1382 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "ok", response.Result, "Response result mismatch") |
| 1383 | } |
| 1384 | |
| 1385 | // TestClient_Post_MultipleHeaderValues tests only first header value is used in POST. |
| 1386 | func TestClient_Post_MultipleHeaderValuesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Post_MultipleHeaderValues().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1387 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1388 | |
| 1389 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 1390 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodPostscip-go gomod github.com/golang/go/src . `net/http`/MethodPost., r.Methodscip-go gomod github.com/golang/go/src . `net/http`/Request#Method., "HTTP method mismatch") |
| 1391 | // The client should only send the first value |
| 1392 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "first-value", r.Headerscip-go gomod github.com/golang/go/src . `net/http`/Request#Header..Getscip-go gomod github.com/golang/go/src . `net/http`/Header#Get().("X-Multi-Header"), "Only first header value should be used") |
| 1393 | |
| 1394 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 1395 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 1396 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"status": "ok"}`)) |
| 1397 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 1398 | })) |
| 1399 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 1400 | |
| 1401 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 1402 | |
| 1403 | // Set multiple values for the same header |
| 1404 | client.Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Headers.()["X-Multi-Header"] = []string{"first-value", "second-value"} |
| 1405 | |
| 1406 | request := struct { |
| 1407 | Name string `json:"name"` |
| 1408 | }{ |
| 1409 | Name: "test", |
| 1410 | } |
| 1411 | |
| 1412 | var response struct { |
| 1413 | Status string `json:"status"` |
| 1414 | } |
| 1415 | |
| 1416 | err := client.Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Post.(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., request, &response) |
| 1417 | |
| 1418 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Post() should not return error") |
| 1419 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "ok", response.Status, "Response status mismatch") |
| 1420 | } |
| 1421 | |
| 1422 | // TestParseResponse_EmptyBodyError tests error response with empty body. |
| 1423 | func TestParseResponse_EmptyBodyErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestParseResponse_EmptyBodyError().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1424 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1425 | |
| 1426 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 1427 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusInternalServerErrorscip-go gomod github.com/golang/go/src . `net/http`/StatusInternalServerError.) |
| 1428 | // Write empty body |
| 1429 | })) |
| 1430 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 1431 | |
| 1432 | req, err := httpscip-go gomod github.com/golang/go/src . `net/http`/.NewRequestWithContextscip-go gomod github.com/golang/go/src . `net/http`/NewRequestWithContext().(contextscip-go gomod github.com/golang/go/src . context/.Backgroundscip-go gomod github.com/golang/go/src . context/Background().(), httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodGetscip-go gomod github.com/golang/go/src . `net/http`/MethodGet., server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., httpscip-go gomod github.com/golang/go/src . `net/http`/.NoBodyscip-go gomod github.com/golang/go/src . `net/http`/NoBody.) |
| 1433 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Failed to create request") |
| 1434 | |
| 1435 | client := &httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#{} |
| 1436 | resp, err := client.Doscip-go gomod github.com/golang/go/src . `net/http`/Client#Do().(req) |
| 1437 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Failed to make request") |
| 1438 | |
| 1439 | defer func() { _ = resp.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 1440 | |
| 1441 | var result any |
| 1442 | |
| 1443 | err = parseResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/parseResponse().(resp, &result) |
| 1444 | |
| 1445 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "parseResponse() should return error for empty error body") |
| 1446 | |
| 1447 | var jsonErr Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error# |
| 1448 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.ErrorAsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/ErrorAs().(t, err, &jsonErr, "Error should be jsonclient.Error") |
| 1449 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusInternalServerErrorscip-go gomod github.com/golang/go/src . `net/http`/StatusInternalServerError., jsonErr.StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode., "StatusCode mismatch") |
| 1450 | } |
| 1451 | |
| 1452 | // TestClient_Get_WithRequestBody tests GET request does not send body. |
| 1453 | func TestClient_Get_WithRequestBodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Get_WithRequestBody().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1454 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1455 | |
| 1456 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 1457 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodGetscip-go gomod github.com/golang/go/src . `net/http`/MethodGet., r.Methodscip-go gomod github.com/golang/go/src . `net/http`/Request#Method., "HTTP method mismatch") |
| 1458 | |
| 1459 | body, err := ioscip-go gomod github.com/golang/go/src . io/.ReadAllscip-go gomod github.com/golang/go/src . io/ReadAll().(r.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body.) |
| 1460 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to read request body") |
| 1461 | |
| 1462 | defer func() { _ = r.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 1463 | |
| 1464 | // GET requests should have no body |
| 1465 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Emptyscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Empty().(t, body, "GET request should have no body") |
| 1466 | |
| 1467 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 1468 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 1469 | _, err = w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"status": "ok"}`)) |
| 1470 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 1471 | })) |
| 1472 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 1473 | |
| 1474 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 1475 | |
| 1476 | var response struct { |
| 1477 | Status string `json:"status"` |
| 1478 | } |
| 1479 | |
| 1480 | err := client.Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Get.(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., &response) |
| 1481 | |
| 1482 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Get() should not return error") |
| 1483 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "ok", response.Status, "Response status mismatch") |
| 1484 | } |
| 1485 | |
| 1486 | // TestClient_Post_NilResponse tests POST with nil response pointer. |
| 1487 | func TestClient_Post_NilResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_Post_NilResponse().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1488 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1489 | |
| 1490 | server := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src . `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src . `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src . `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) { |
| 1491 | w.Headerscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.) |
| 1492 | w.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 1493 | _, err := w.Writescip-go gomod github.com/golang/go/src . `net/http`/ResponseWriter#Write().([]byte(`{"status": "ok"}`)) |
| 1494 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Failed to write response") |
| 1495 | })) |
| 1496 | defer server.Closescip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#Close().() |
| 1497 | |
| 1498 | client := NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 1499 | |
| 1500 | request := struct { |
| 1501 | Name string `json:"name"` |
| 1502 | }{ |
| 1503 | Name: "test", |
| 1504 | } |
| 1505 | |
| 1506 | // Pass nil as response - should still work but not unmarshal |
| 1507 | err := client.Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Post.(server.URLscip-go gomod github.com/golang/go/src . `net/http/httptest`/Server#URL., request, nil) |
| 1508 | |
| 1509 | // This will fail because json.Unmarshal doesn't accept nil |
| 1510 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "Post() should return error for nil response") |
| 1511 | } |
| 1512 | |
| 1513 | // TestParseResponse_NilBody tests parseResponse with nil body handling. |
| 1514 | func TestParseResponse_NilBodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestParseResponse_NilBody().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1515 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1516 | |
| 1517 | // Create a response with nil body using httptest |
| 1518 | recorder := httptestscip-go gomod github.com/golang/go/src . `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src . `net/http/httptest`/NewRecorder().() |
| 1519 | recorder.WriteHeaderscip-go gomod github.com/golang/go/src . `net/http/httptest`/ResponseRecorder#WriteHeader().(httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK.) |
| 1520 | |
| 1521 | // Create a response manually with a nil body reader |
| 1522 | resp := &httpscip-go gomod github.com/golang/go/src . `net/http`/.Responsescip-go gomod github.com/golang/go/src . `net/http`/Response#{ |
| 1523 | StatusCodescip-go gomod github.com/golang/go/src . `net/http`/Response#StatusCode.: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK., |
| 1524 | Headerscip-go gomod github.com/golang/go/src . `net/http`/Response#Header.: httpscip-go gomod github.com/golang/go/src . `net/http`/.Headerscip-go gomod github.com/golang/go/src . `net/http`/Header#{"Content-Type": []string{ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.}}, |
| 1525 | Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body.: ioscip-go gomod github.com/golang/go/src . io/.NopCloserscip-go gomod github.com/golang/go/src . io/NopCloser().(bytesscip-go gomod github.com/golang/go/src . bytes/.NewReaderscip-go gomod github.com/golang/go/src . bytes/NewReader().([]byte(`{"data": "test"}`))), |
| 1526 | } |
| 1527 | |
| 1528 | var result struct { |
| 1529 | Data string `json:"data"` |
| 1530 | } |
| 1531 | |
| 1532 | err := parseResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/parseResponse().(resp, &result) |
| 1533 | |
| 1534 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "parseResponse() should not return error") |
| 1535 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "test", result.Data, "Data mismatch") |
| 1536 | } |
| 1537 | |
| 1538 | // TestClient_NewWithHTTPClient_NilClient tests NewWithHTTPClient with nil client. |
| 1539 | func TestClient_NewWithHTTPClient_NilClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestClient_NewWithHTTPClient_NilClient().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1540 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1541 | |
| 1542 | // This should work but may panic when used - test the constructor |
| 1543 | client := NewWithHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewWithHTTPClient().(nil) |
| 1544 | |
| 1545 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NotNil().(t, client, "NewWithHTTPClient(nil) should return non-nil client") |
| 1546 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NotNil().(t, client.Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Headers.(), "Headers() should not return nil") |
| 1547 | } |
| 1548 | |
| 1549 | // TestError_Unwrap tests error unwrapping capabilities. |
| 1550 | func TestError_Unwrapscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/TestError_Unwrap().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 1551 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 1552 | |
| 1553 | innerErr := errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("inner error") |
| 1554 | jsonErr := Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#{ |
| 1555 | StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode.: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src . `net/http`/StatusBadRequest., |
| 1556 | Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body.: `{"error": "bad request"}`, |
| 1557 | errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err.: innerErr, |
| 1558 | } |
| 1559 | |
| 1560 | // Error() and String() should return the inner error message |
| 1561 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "inner error", jsonErr.Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Error().(), "Error() should return inner error") |
| 1562 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "inner error", jsonErr.Stringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#String().(), "String() should return inner error") |
| 1563 | |
| 1564 | // Test with nil inner error |
| 1565 | jsonErrNil := Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#{ |
| 1566 | StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode.: httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusInternalServerErrorscip-go gomod github.com/golang/go/src . `net/http`/StatusInternalServerError., |
| 1567 | Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body.: "", |
| 1568 | errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err.: nil, |
| 1569 | } |
| 1570 | |
| 1571 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "unknown error (HTTP 500)", jsonErrNil.Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Error().(), "Error() should return generic message") |
| 1572 | assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "unknown error (HTTP 500)", jsonErrNil.Stringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#String().(), "String() should return generic message") |
| 1573 | } |