Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b42404d293 |
@@ -0,0 +1,40 @@
|
||||
package awsserversdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRetryCreatePreservesIdentityAndKeyOnTransientFailure(t *testing.T) {
|
||||
requests := 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
requests++
|
||||
if r.Method != "POST" || r.URL.Path != "/api/sdk/v1/regions/us-east-1/instances/local-1/retry" || r.Header.Get("Idempotency-Key") != "create-retry:1:2" {
|
||||
t.Errorf("unexpected retry request: %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
var body map[string]any
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil || len(body) != 0 {
|
||||
t.Errorf("retry payload must not select another account: %v %v", body, err)
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if requests == 1 {
|
||||
w.WriteHeader(503)
|
||||
w.Write([]byte(`{"code":503,"message":"temporarily unavailable"}`))
|
||||
return
|
||||
}
|
||||
w.WriteHeader(202)
|
||||
w.Write([]byte(`{"code":202,"data":{"id":"local-1","task_id":"retry-task","placement_id":"original"}}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
client, err := NewClient(server.URL, "awsapp_test_secret", WithMaxRetries(1))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
operation, err := client.Instances.RetryCreate(context.Background(), "us-east-1", "local-1", WithIdempotencyKey("create-retry:1:2"))
|
||||
if err != nil || operation.ID != "local-1" || operation.TaskID != "retry-task" || operation.PlacementID != "original" || requests != 2 {
|
||||
t.Fatalf("result=%+v requests=%d err=%v", operation, requests, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user