Download this file
| 1 | package client |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "net/http" |
| 6 | "net/http/httptest" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | |
| 10 | access "amadan.net/oficina/agent-access.git" |
| 11 | ) |
| 12 | |
| 13 | func TestRemoteFailuresRetainCategoryWithoutRemoteContent(t *testing.T) { |
| 14 | for status, code := range map[int]string{401: "unauthenticated", 403: "forbidden", 404: "not_found", 409: "conflict", 413: "too_large", 415: "unsupported_media_type", 422: "invalid", 429: "rate_limited", 500: "internal", 503: "unavailable", 302: "unavailable"} { |
| 15 | t.Run(code, func(t *testing.T) { |
| 16 | s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 17 | w.WriteHeader(status) |
| 18 | w.Write([]byte(`{"error":{"code":"forbidden","message":"private-document-marker"}}`)) |
| 19 | })) |
| 20 | defer s.Close() |
| 21 | c := New(nil) |
| 22 | req, _ := http.NewRequest("GET", s.URL, nil) |
| 23 | var out any |
| 24 | err := c.readJSON(t.Context(), req, &out) |
| 25 | var failure access.Failure |
| 26 | if !errors.As(err, &failure) || failure.Code != code || strings.Contains(err.Error(), "private-document-marker") { |
| 27 | t.Fatalf("%d: %v", status, err) |
| 28 | } |
| 29 | }) |
| 30 | } |
| 31 | } |
| 32 | |