forked from mtusi2026/mtusi2026lab4
лаба 4 на оценку 5
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
@@ -133,7 +134,7 @@ func TestMessageIdempotencyReplayAndConflict(t *testing.T) {
|
||||
|
||||
first := decodeMessageResponse(t, firstPayload)
|
||||
replay := decodeMessageResponse(t, replayPayload)
|
||||
if first != replay {
|
||||
if !reflect.DeepEqual(first, replay) {
|
||||
t.Fatalf("replay changed message: first=%+v replay=%+v", first, replay)
|
||||
}
|
||||
|
||||
@@ -256,7 +257,7 @@ func TestConcurrentMessageIdempotencyCreatesExactlyOneMessage(t *testing.T) {
|
||||
for message := range results {
|
||||
if count == 0 {
|
||||
expected = message
|
||||
} else if message != expected {
|
||||
} else if !reflect.DeepEqual(message, expected) {
|
||||
t.Fatalf("concurrent replay returned different message: %+v != %+v", message, expected)
|
||||
}
|
||||
count++
|
||||
@@ -273,3 +274,40 @@ func TestConcurrentMessageIdempotencyCreatesExactlyOneMessage(t *testing.T) {
|
||||
t.Fatalf("expected exactly one stored message, got %d", len(messages))
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageIdempotencyTreatsMissingAndEmptyAttachmentsEqually(t *testing.T) {
|
||||
_, serverURL, user, chatID := createMessageFixture(t)
|
||||
|
||||
status, firstPayload := sendMessageRequest(
|
||||
t,
|
||||
serverURL,
|
||||
chatID,
|
||||
user.ID,
|
||||
"default-attachments",
|
||||
`{"text":"same semantic request"}`,
|
||||
)
|
||||
if status != http.StatusCreated {
|
||||
t.Fatalf("first request: expected 201, got %d: %s", status, firstPayload)
|
||||
}
|
||||
|
||||
status, replayPayload := sendMessageRequest(
|
||||
t,
|
||||
serverURL,
|
||||
chatID,
|
||||
user.ID,
|
||||
"default-attachments",
|
||||
`{"attachment_ids":[],"text":"same semantic request"}`,
|
||||
)
|
||||
if status != http.StatusCreated {
|
||||
t.Fatalf("replay: expected 201, got %d: %s", status, replayPayload)
|
||||
}
|
||||
|
||||
first := decodeMessageResponse(t, firstPayload)
|
||||
replay := decodeMessageResponse(t, replayPayload)
|
||||
if !reflect.DeepEqual(first, replay) {
|
||||
t.Fatalf("missing attachment_ids and [] must replay identically")
|
||||
}
|
||||
if first.AttachmentIDs == nil || len(first.AttachmentIDs) != 0 {
|
||||
t.Fatalf("response must contain attachment_ids: [], got %#v", first.AttachmentIDs)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user