forked from mtusi2026/mtusi2026lab4
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package integration
|
|
|
|
import (
|
|
"backend/internal/adapter/storage"
|
|
"backend/internal/domain/port"
|
|
"bytes"
|
|
"context"
|
|
"github.com/google/uuid"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestS3InventoryAndStatReturnComparableVersionMetadata(t *testing.T) {
|
|
if os.Getenv("RUN_ISOLATED_RECONCILIATION") != "1" {
|
|
t.Skip("explicit isolated stand required")
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
|
defer cancel()
|
|
cfg, e := storage.ReadConfig("/run/secrets/s3_credentials")
|
|
if e != nil {
|
|
t.Fatal("configuration unavailable")
|
|
}
|
|
s, e := storage.FromConfig(cfg)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
key := "originals/" + uuid.NewString()
|
|
defer func() {
|
|
if err := s.Remove(context.Background(), key); err != nil {
|
|
t.Error("object fixture cleanup failed")
|
|
}
|
|
}()
|
|
if e = s.Put(ctx, key, bytes.NewReader([]byte("synthetic-version-probe")), 23, "application/octet-stream"); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
stat, e := s.Stat(ctx, key)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
var listed port.Object
|
|
after := ""
|
|
found := false
|
|
for page := 0; page < 10; page++ {
|
|
rows, more, e := s.List(ctx, after)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
for _, row := range rows {
|
|
if row.Key == key {
|
|
listed = row
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if found || !more {
|
|
break
|
|
}
|
|
after = rows[len(rows)-1].Key
|
|
}
|
|
if !found {
|
|
t.Fatal("own object absent from bounded inventory")
|
|
}
|
|
if listed.ETag != stat.ETag || listed.Size != stat.Size || !listed.Modified.Equal(stat.Modified) {
|
|
t.Fatalf("inconsistent version metadata: etag_equal=%t size_equal=%t list_time=%s stat_time=%s", listed.ETag == stat.ETag, listed.Size == stat.Size, listed.Modified.Format(time.RFC3339Nano), stat.Modified.Format(time.RFC3339Nano))
|
|
}
|
|
}
|