| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| 6 | "io" |
| 7 | "net/http" |
| 8 | "net/http/httptest" |
| 9 | "testing" |
| 10 | ) |
| 11 | |
| 12 | func TestAPISessionInstanceRetryWireShape(t *testing.T) { |
| 13 | var path, body string |
| 14 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 15 | b, _ := io.ReadAll(r.Body) |
| 16 | path, body = r.URL.Path, string(b) |
| 17 | w.Header().Set("Content-Type", "application/json") |
| 18 | io.WriteString(w, `{"result":"requested","id":"r1","version":"v2","host":"a.shop.test"}`) |
| 19 | })) |
| 20 | defer ts.Close() |
| 21 | res, err := newTestSession(ts.URL).instanceRetry(context.Background(), apiAcct{Seg: "bab"}, "shop", "a.shop.test") |
| 22 | if err != nil || res.Version != "v2" || res.ID != "r1" { |
| 23 | t.Fatalf("instanceRetry = %+v, %v", res, err) |
| 24 | } |
| 25 | if path != "/api/cli/apps/bab/shop/instances/a.shop.test/retry" || body != `{}` { |
| 26 | t.Fatalf("sent %s %s", path, body) |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | func TestAPISessionInstanceRetryOldConsole(t *testing.T) { |
| 31 | ts := httptest.NewServer(http.NotFoundHandler()) |
| 32 | defer ts.Close() |
| 33 | _, err := newTestSession(ts.URL).instanceRetry(context.Background(), apiAcct{Seg: "bab"}, "shop", "a.shop.test") |
| 34 | if err == nil || err.Error() != fmt.Sprintf(instancesRetryOldConsole, "shop", "a.shop.test") { |
| 35 | t.Fatalf("err = %v", err) |
| 36 | } |
| 37 | } |
| 38 | |