forked from longtao.wu/droboticflow
484 lines
19 KiB
Go
484 lines
19 KiB
Go
package api
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"droboticflow/internal/config"
|
|
"droboticflow/internal/domain"
|
|
"droboticflow/internal/store"
|
|
)
|
|
|
|
func objectSyncTestHandler(t *testing.T, enabled bool) (http.Handler, *store.MemoryStore) {
|
|
t.Helper()
|
|
dataStore := store.NewMemoryStore()
|
|
if err := dataStore.UpsertStorageConnection(t.Context(), domain.StorageConnectionRecord{
|
|
ID: "bos-connection",
|
|
OrganizationID: domain.DefaultOrganizationID,
|
|
Name: "BOS",
|
|
Provider: domain.StorageProviderBOS,
|
|
Endpoint: "https://bj.bcebos.com",
|
|
AccessKeyID: "masked-in-api",
|
|
SecretAccessKey: "masked-in-api",
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return NewHandlerWithConfig(dataStore, nil, config.AppConfig{
|
|
ObjectSyncEnabled: enabled,
|
|
WorkspaceMountPath: "/workspace",
|
|
}), dataStore
|
|
}
|
|
|
|
func objectSyncRequest(t *testing.T, handler http.Handler, method, target string, payload any, idempotencyKey string) *httptest.ResponseRecorder {
|
|
t.Helper()
|
|
var body bytes.Buffer
|
|
if payload != nil {
|
|
if err := json.NewEncoder(&body).Encode(payload); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
request := httptest.NewRequest(method, target, &body)
|
|
request.Header.Set("Content-Type", "application/json")
|
|
if idempotencyKey != "" {
|
|
request.Header.Set("Idempotency-Key", idempotencyKey)
|
|
}
|
|
writer := httptest.NewRecorder()
|
|
handler.ServeHTTP(writer, request)
|
|
return writer
|
|
}
|
|
|
|
func TestObjectSyncFeatureFlagBlocksAllRoutes(t *testing.T) {
|
|
handler, _ := objectSyncTestHandler(t, false)
|
|
writer := objectSyncRequest(t, handler, http.MethodGet, "/api/object-sync/spaces", nil, "")
|
|
if writer.Code != http.StatusServiceUnavailable {
|
|
t.Fatalf("status = %d, want %d; body=%s", writer.Code, http.StatusServiceUnavailable, writer.Body.String())
|
|
}
|
|
var response objectSyncAPIError
|
|
if err := json.Unmarshal(writer.Body.Bytes(), &response); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if response.Code != "object_sync_disabled" || response.RequestID == "" {
|
|
t.Fatalf("unexpected error envelope: %#v", response)
|
|
}
|
|
}
|
|
|
|
func TestObjectSyncSpaceStartsBlockedAndCannotBypassCapabilityGate(t *testing.T) {
|
|
handler, _ := objectSyncTestHandler(t, true)
|
|
create := objectSyncRequest(t, handler, http.MethodPost, "/api/object-sync/spaces", map[string]any{
|
|
"name": "Robot uploads",
|
|
"connectionId": "bos-connection",
|
|
"bucket": "robot-data",
|
|
"rootPrefix": "incoming",
|
|
}, "space-create")
|
|
if create.Code != http.StatusCreated {
|
|
t.Fatalf("status = %d; body=%s", create.Code, create.Body.String())
|
|
}
|
|
var space domain.ObjectSyncSpaceRecord
|
|
if err := json.Unmarshal(create.Body.Bytes(), &space); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if space.Enabled || space.Mode != "blocked" || space.Capability.State != domain.ObjectSyncCapabilityUnverified {
|
|
t.Fatalf("space bypassed initial gate: %#v", space)
|
|
}
|
|
enable := objectSyncRequest(t, handler, http.MethodPut, "/api/object-sync/spaces/"+space.ID, map[string]any{
|
|
"enabled": true,
|
|
}, "space-enable")
|
|
if enable.Code != http.StatusConflict {
|
|
t.Fatalf("status = %d, want conflict; body=%s", enable.Code, enable.Body.String())
|
|
}
|
|
}
|
|
|
|
func TestObjectSyncDriftStateCannotBeClearedBySettingsUpdate(t *testing.T) {
|
|
handler, dataStore := objectSyncTestHandler(t, true)
|
|
target, _ := store.AsObjectSyncStore(dataStore)
|
|
policy := domain.DefaultObjectSyncSpacePolicy()
|
|
policy.AllowConditionalUpdate = true
|
|
policy.AllowForceOverwrite = true
|
|
space := domain.ObjectSyncSpaceRecord{
|
|
ID: "space-drifted",
|
|
OrganizationID: domain.DefaultOrganizationID,
|
|
ConnectionID: "bos-connection",
|
|
Bucket: "robot-data",
|
|
Enabled: false,
|
|
Mode: "blocked",
|
|
Policy: policy,
|
|
Capability: domain.ObjectSyncCapabilityRecord{
|
|
State: domain.ObjectSyncCapabilityDrifted,
|
|
ConditionalCreate: true,
|
|
ConditionalUpdate: true,
|
|
ConditionalMultipart: true,
|
|
ExclusivePrefixConfirmed: true,
|
|
},
|
|
CreatedAt: "2026-07-28T08:00:00Z",
|
|
UpdatedAt: "2026-07-28T08:00:00Z",
|
|
}
|
|
if err := target.UpsertObjectSyncSpace(t.Context(), space); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
writer := objectSyncRequest(t, handler, http.MethodPut, "/api/object-sync/spaces/"+space.ID, map[string]any{
|
|
"name": "renamed but still drifted",
|
|
"enabled": true,
|
|
}, "drift-settings-update")
|
|
if writer.Code != http.StatusConflict {
|
|
t.Fatalf("status = %d; body=%s", writer.Code, writer.Body.String())
|
|
}
|
|
stored, err := target.GetObjectSyncSpace(t.Context(), space.ID)
|
|
if err != nil || stored == nil {
|
|
t.Fatalf("stored space: %#v, %v", stored, err)
|
|
}
|
|
if stored.Capability.State != domain.ObjectSyncCapabilityDrifted || stored.Enabled {
|
|
t.Fatalf("drift gate was bypassed: %#v", stored)
|
|
}
|
|
}
|
|
|
|
func TestObjectSyncWritesRequireIdempotencyKey(t *testing.T) {
|
|
handler, _ := objectSyncTestHandler(t, true)
|
|
writer := objectSyncRequest(t, handler, http.MethodPost, "/api/object-sync/spaces", map[string]any{
|
|
"name": "Robot uploads",
|
|
"connectionId": "bos-connection",
|
|
"bucket": "robot-data",
|
|
}, "")
|
|
if writer.Code != http.StatusBadRequest {
|
|
t.Fatalf("status = %d; body=%s", writer.Code, writer.Body.String())
|
|
}
|
|
var response objectSyncAPIError
|
|
if err := json.Unmarshal(writer.Body.Bytes(), &response); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if response.Code != "idempotency_key_required" {
|
|
t.Fatalf("code = %q", response.Code)
|
|
}
|
|
}
|
|
|
|
func TestObjectSyncIdempotencyReplaysCompletedResponse(t *testing.T) {
|
|
handler, _ := objectSyncTestHandler(t, true)
|
|
payload := map[string]any{
|
|
"name": "Robot uploads",
|
|
"connectionId": "bos-connection",
|
|
"bucket": "robot-data",
|
|
}
|
|
first := objectSyncRequest(t, handler, http.MethodPost, "/api/object-sync/spaces", payload, "replay-space")
|
|
second := objectSyncRequest(t, handler, http.MethodPost, "/api/object-sync/spaces", payload, "replay-space")
|
|
if first.Code != http.StatusCreated || second.Code != first.Code {
|
|
t.Fatalf("statuses = %d, %d; first=%s second=%s", first.Code, second.Code, first.Body.String(), second.Body.String())
|
|
}
|
|
if first.Body.String() != second.Body.String() {
|
|
t.Fatalf("replayed response changed:\nfirst=%s\nsecond=%s", first.Body.String(), second.Body.String())
|
|
}
|
|
if second.Header().Get("Idempotency-Replayed") != "true" {
|
|
t.Fatalf("missing replay header: %#v", second.Header())
|
|
}
|
|
}
|
|
|
|
func TestObjectSyncIdempotencyRejectsKeyReuseWithDifferentPayload(t *testing.T) {
|
|
handler, _ := objectSyncTestHandler(t, true)
|
|
first := objectSyncRequest(t, handler, http.MethodPost, "/api/object-sync/spaces", map[string]any{
|
|
"name": "Robot uploads",
|
|
"connectionId": "bos-connection",
|
|
"bucket": "robot-data",
|
|
}, "reused-space-key")
|
|
if first.Code != http.StatusCreated {
|
|
t.Fatalf("first status = %d; body=%s", first.Code, first.Body.String())
|
|
}
|
|
second := objectSyncRequest(t, handler, http.MethodPost, "/api/object-sync/spaces", map[string]any{
|
|
"name": "Different uploads",
|
|
"connectionId": "bos-connection",
|
|
"bucket": "robot-data",
|
|
}, "reused-space-key")
|
|
if second.Code != http.StatusConflict {
|
|
t.Fatalf("second status = %d; body=%s", second.Code, second.Body.String())
|
|
}
|
|
var response objectSyncAPIError
|
|
if err := json.Unmarshal(second.Body.Bytes(), &response); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if response.Code != "idempotency_key_reused" {
|
|
t.Fatalf("code = %q", response.Code)
|
|
}
|
|
}
|
|
|
|
func TestObjectSyncClientReleaseArtifactsAreImmutable(t *testing.T) {
|
|
handler, dataStore := objectSyncTestHandler(t, true)
|
|
target, _ := store.AsObjectSyncStore(dataStore)
|
|
release := map[string]any{
|
|
"id": "drosync-1.0.0",
|
|
"version": "1.0.0",
|
|
"channel": "canary",
|
|
"protocolVersion": "v1",
|
|
"rolloutPercent": 5,
|
|
"paused": false,
|
|
"artifacts": map[string]string{"linux-x86_64": "https://downloads.example/drosync.deb"},
|
|
"sha256": map[string]string{"linux-x86_64": strings.Repeat("a", 64)},
|
|
"signature": "signed-manifest",
|
|
}
|
|
created := objectSyncRequest(t, handler, http.MethodPost, "/api/object-sync/client-releases", release, "release-create")
|
|
if created.Code != http.StatusOK {
|
|
t.Fatalf("status = %d; body=%s", created.Code, created.Body.String())
|
|
}
|
|
items, err := target.ListObjectSyncClientReleases(t.Context())
|
|
if err != nil || len(items) != 1 {
|
|
t.Fatalf("stored releases = %#v, %v", items, err)
|
|
}
|
|
items[0].StageChangedAt = time.Now().UTC().Add(-25 * time.Hour).Format(time.RFC3339Nano)
|
|
if err := target.UpsertObjectSyncClientRelease(t.Context(), items[0]); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
release["channel"] = "pilot"
|
|
release["rolloutPercent"] = 20
|
|
advanced := objectSyncRequest(t, handler, http.MethodPost, "/api/object-sync/client-releases", release, "release-pilot")
|
|
if advanced.Code != http.StatusOK {
|
|
t.Fatalf("advance status = %d; body=%s", advanced.Code, advanced.Body.String())
|
|
}
|
|
release["artifacts"] = map[string]string{"linux-x86_64": "https://attacker.example/replaced.deb"}
|
|
rejected := objectSyncRequest(t, handler, http.MethodPost, "/api/object-sync/client-releases", release, "release-mutate")
|
|
if rejected.Code != http.StatusConflict {
|
|
t.Fatalf("mutation status = %d; body=%s", rejected.Code, rejected.Body.String())
|
|
}
|
|
}
|
|
|
|
func TestObjectSyncClientReleasePromotionRequiresObservationWindow(t *testing.T) {
|
|
handler, _ := objectSyncTestHandler(t, true)
|
|
release := map[string]any{
|
|
"id": "drosync-2.0.0",
|
|
"version": "2.0.0",
|
|
"channel": "canary",
|
|
"protocolVersion": "v1",
|
|
"rolloutPercent": 5,
|
|
"paused": false,
|
|
"artifacts": map[string]string{"linux-x86_64": "https://downloads.example/drosync.deb"},
|
|
"sha256": map[string]string{"linux-x86_64": strings.Repeat("b", 64)},
|
|
"signature": "signed-manifest",
|
|
}
|
|
created := objectSyncRequest(t, handler, http.MethodPost, "/api/object-sync/client-releases", release, "release-observe-create")
|
|
if created.Code != http.StatusOK {
|
|
t.Fatalf("create status = %d; body=%s", created.Code, created.Body.String())
|
|
}
|
|
release["channel"] = "pilot"
|
|
release["rolloutPercent"] = 20
|
|
promoted := objectSyncRequest(t, handler, http.MethodPost, "/api/object-sync/client-releases", release, "release-observe-promote")
|
|
if promoted.Code != http.StatusConflict {
|
|
t.Fatalf("promotion status = %d; body=%s", promoted.Code, promoted.Body.String())
|
|
}
|
|
var response objectSyncAPIError
|
|
if err := json.Unmarshal(promoted.Body.Bytes(), &response); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if response.Code != "rollout_observation_incomplete" {
|
|
t.Fatalf("code = %q", response.Code)
|
|
}
|
|
}
|
|
|
|
func TestObjectSyncDeviceAuthorizationIsPublicAndReturnsShortCode(t *testing.T) {
|
|
handler, _ := objectSyncTestHandler(t, true)
|
|
writer := objectSyncRequest(t, handler, http.MethodPost, "/api/external/object-sync/device-authorizations", map[string]any{
|
|
"deviceId": "device-01",
|
|
"deviceName": "capture-station",
|
|
"platform": "linux",
|
|
"architecture": "x86_64",
|
|
"clientVersion": "1.0.0",
|
|
}, "pair-device")
|
|
if writer.Code != http.StatusCreated {
|
|
t.Fatalf("status = %d; body=%s", writer.Code, writer.Body.String())
|
|
}
|
|
var response map[string]any
|
|
if err := json.Unmarshal(writer.Body.Bytes(), &response); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if response["deviceCode"] == "" || response["userCode"] == "" || response["verificationUri"] == "" {
|
|
t.Fatalf("pairing response is incomplete: %#v", response)
|
|
}
|
|
lookup := objectSyncRequest(t, handler, http.MethodGet, "/api/object-sync/device-authorizations/by-code?userCode="+response["userCode"].(string), nil, "")
|
|
if lookup.Code != http.StatusOK {
|
|
t.Fatalf("lookup status = %d; body=%s", lookup.Code, lookup.Body.String())
|
|
}
|
|
var authorization domain.ObjectSyncDeviceAuthorizationRecord
|
|
if err := json.Unmarshal(lookup.Body.Bytes(), &authorization); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if authorization.DeviceID != "device-01" || authorization.Status != "pending" {
|
|
t.Fatalf("unexpected authorization lookup: %#v", authorization)
|
|
}
|
|
}
|
|
|
|
func TestObjectSyncPublicPairingUsesDistributedRateLimit(t *testing.T) {
|
|
handler, _ := objectSyncTestHandler(t, true)
|
|
for index := 0; index < 30; index++ {
|
|
writer := objectSyncRequest(t, handler, http.MethodPost, "/api/external/object-sync/device-authorizations", map[string]any{
|
|
"deviceId": "rate-device",
|
|
"deviceName": "rate-test",
|
|
"platform": "linux",
|
|
"architecture": "x86_64",
|
|
}, "rate-pair-"+strconv.Itoa(index))
|
|
if writer.Code != http.StatusCreated {
|
|
t.Fatalf("request %d status = %d; body=%s", index+1, writer.Code, writer.Body.String())
|
|
}
|
|
}
|
|
blocked := objectSyncRequest(t, handler, http.MethodPost, "/api/external/object-sync/device-authorizations", map[string]any{
|
|
"deviceId": "rate-device",
|
|
"deviceName": "rate-test",
|
|
"platform": "linux",
|
|
"architecture": "x86_64",
|
|
}, "rate-pair-blocked")
|
|
if blocked.Code != http.StatusTooManyRequests {
|
|
t.Fatalf("status = %d, want %d; body=%s", blocked.Code, http.StatusTooManyRequests, blocked.Body.String())
|
|
}
|
|
if blocked.Header().Get("Retry-After") == "" || blocked.Header().Get("RateLimit-Remaining") != "0" {
|
|
t.Fatalf("missing rate limit headers: %#v", blocked.Header())
|
|
}
|
|
}
|
|
|
|
func TestObjectSyncSessionsUseOpaqueCursorPagination(t *testing.T) {
|
|
handler, dataStore := objectSyncTestHandler(t, true)
|
|
target, _ := store.AsObjectSyncStore(dataStore)
|
|
for _, id := range []string{"session-a", "session-b", "session-c"} {
|
|
if err := target.UpsertObjectSyncSession(t.Context(), domain.ObjectSyncSessionRecord{
|
|
ID: id,
|
|
OrganizationID: domain.DefaultOrganizationID,
|
|
Status: domain.ObjectSyncSessionRunning,
|
|
CreatedAt: "2026-07-28T08:00:00Z",
|
|
UpdatedAt: "2026-07-28T08:00:00Z",
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
first := objectSyncRequest(t, handler, http.MethodGet, "/api/object-sync/sessions?limit=2", nil, "")
|
|
if first.Code != http.StatusOK {
|
|
t.Fatalf("first status = %d; body=%s", first.Code, first.Body.String())
|
|
}
|
|
var firstPage domain.ObjectSyncSessionPage
|
|
if err := json.Unmarshal(first.Body.Bytes(), &firstPage); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(firstPage.Items) != 2 || firstPage.NextCursor == "" || strings.Contains(firstPage.NextCursor, "session-") {
|
|
t.Fatalf("unexpected first page: %#v", firstPage)
|
|
}
|
|
second := objectSyncRequest(t, handler, http.MethodGet, "/api/object-sync/sessions?limit=2&cursor="+firstPage.NextCursor, nil, "")
|
|
if second.Code != http.StatusOK {
|
|
t.Fatalf("second status = %d; body=%s", second.Code, second.Body.String())
|
|
}
|
|
var secondPage domain.ObjectSyncSessionPage
|
|
if err := json.Unmarshal(second.Body.Bytes(), &secondPage); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(secondPage.Items) != 1 || secondPage.NextCursor != "" {
|
|
t.Fatalf("unexpected second page: %#v", secondPage)
|
|
}
|
|
}
|
|
|
|
func TestObjectSyncForceOverwriteQueuesSeparateAuditedItem(t *testing.T) {
|
|
handler, dataStore := objectSyncTestHandler(t, true)
|
|
target, _ := store.AsObjectSyncStore(dataStore)
|
|
policy := domain.DefaultObjectSyncSpacePolicy()
|
|
policy.AllowConditionalUpdate = true
|
|
policy.AllowForceOverwrite = true
|
|
space := domain.ObjectSyncSpaceRecord{
|
|
ID: "space-force",
|
|
OrganizationID: domain.DefaultOrganizationID,
|
|
ConnectionID: "bos-connection",
|
|
Bucket: "robot-data",
|
|
Enabled: true,
|
|
Mode: "update_enabled",
|
|
Policy: policy,
|
|
Capability: domain.ObjectSyncCapabilityRecord{
|
|
State: domain.ObjectSyncCapabilityUpdateEnabled,
|
|
ConditionalCreate: true,
|
|
ConditionalUpdate: true,
|
|
ConditionalMultipart: true,
|
|
ExclusivePrefixConfirmed: true,
|
|
},
|
|
CreatedAt: "2026-07-28T08:00:00Z",
|
|
UpdatedAt: "2026-07-28T08:00:00Z",
|
|
}
|
|
if err := target.UpsertObjectSyncSpace(t.Context(), space); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
session := domain.ObjectSyncSessionRecord{
|
|
ID: "session-force",
|
|
OrganizationID: domain.DefaultOrganizationID,
|
|
SyncSpaceID: space.ID,
|
|
Status: domain.ObjectSyncSessionConflicted,
|
|
CreatedAt: "2026-07-28T08:00:00Z",
|
|
UpdatedAt: "2026-07-28T08:00:00Z",
|
|
}
|
|
if err := target.UpsertObjectSyncSession(t.Context(), session); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
conflict := domain.ObjectSyncItemRecord{
|
|
ID: "item-conflict",
|
|
OrganizationID: domain.DefaultOrganizationID,
|
|
SessionID: session.ID,
|
|
ClientItemID: "client-conflict",
|
|
TargetKey: "incoming/file.bin.__conflict__20260728T000000Z_source",
|
|
LogicalTargetKey: "incoming/file.bin",
|
|
SizeBytes: 4,
|
|
SHA256: "abcd",
|
|
Status: domain.ObjectSyncItemKeptBoth,
|
|
CreatedAt: "2026-07-28T08:00:00Z",
|
|
UpdatedAt: "2026-07-28T08:00:00Z",
|
|
}
|
|
if err := target.UpsertObjectSyncItems(t.Context(), []domain.ObjectSyncItemRecord{conflict}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
writer := objectSyncRequest(t, handler, http.MethodPost, "/api/object-sync/items/"+conflict.ID+"/force-overwrite", map[string]any{}, "force-overwrite")
|
|
if writer.Code != http.StatusAccepted {
|
|
t.Fatalf("status = %d; body=%s", writer.Code, writer.Body.String())
|
|
}
|
|
page, err := target.ListObjectSyncItems(t.Context(), domain.ObjectSyncListQuery{SessionID: session.ID, Limit: 10})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(page.Items) != 2 {
|
|
t.Fatalf("items = %#v", page.Items)
|
|
}
|
|
original, err := target.GetObjectSyncItem(t.Context(), conflict.ID)
|
|
if err != nil || original == nil || original.Status != domain.ObjectSyncItemKeptBoth {
|
|
t.Fatalf("original conflict was mutated: %#v, %v", original, err)
|
|
}
|
|
var queued *domain.ObjectSyncItemRecord
|
|
for index := range page.Items {
|
|
if page.Items[index].ID != conflict.ID {
|
|
queued = &page.Items[index]
|
|
}
|
|
}
|
|
if queued == nil || queued.Action != "force_overwrite" || queued.ForceSourceKey != conflict.TargetKey || queued.Status != domain.ObjectSyncItemCommitting {
|
|
t.Fatalf("queued force item = %#v", queued)
|
|
}
|
|
}
|
|
|
|
func TestObjectSyncReleaseRejectsSessionsAcrossSpaces(t *testing.T) {
|
|
handler, dataStore := objectSyncTestHandler(t, true)
|
|
target, _ := store.AsObjectSyncStore(dataStore)
|
|
for index, spaceID := range []string{"space-a", "space-b"} {
|
|
if err := target.UpsertObjectSyncSession(t.Context(), domain.ObjectSyncSessionRecord{
|
|
ID: "release-session-" + strconv.Itoa(index),
|
|
OrganizationID: domain.DefaultOrganizationID,
|
|
SyncSpaceID: spaceID,
|
|
Status: domain.ObjectSyncSessionCompleted,
|
|
CreatedAt: "2026-07-28T08:00:00Z",
|
|
UpdatedAt: "2026-07-28T08:00:00Z",
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
writer := objectSyncRequest(t, handler, http.MethodPost, "/api/object-sync/releases", map[string]any{
|
|
"name": "ambiguous-release",
|
|
"sessionIds": []string{"release-session-0", "release-session-1"},
|
|
}, "release-cross-space")
|
|
if writer.Code != http.StatusConflict {
|
|
t.Fatalf("status = %d; body=%s", writer.Code, writer.Body.String())
|
|
}
|
|
var response objectSyncAPIError
|
|
if err := json.Unmarshal(writer.Body.Bytes(), &response); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if response.Code != "release_space_mismatch" {
|
|
t.Fatalf("code = %q", response.Code)
|
|
}
|
|
}
|