package httpapi

import (
	"net/http/httptest"
	"testing"
)

func TestSingleIdempotencyKey(t *testing.T) {
	t.Parallel()

	request := httptest.NewRequest("POST", "/", nil)
	request.Header.Add("Idempotency-Key", "retry-1")
	if got, ok := singleIdempotencyKey(request); !ok || got != "retry-1" {
		t.Fatalf("got key=%q ok=%v", got, ok)
	}

	request.Header.Add("Idempotency-Key", "retry-2")
	if _, ok := singleIdempotencyKey(request); ok {
		t.Fatal("multiple Idempotency-Key values must be rejected")
	}
}
