package main // 🤖 Runs the backend-agnostic vaultStore contract suite (store_test.go) // against a REAL S3 bucket — conditional-write semantics are exactly the kind // of thing a fake gets subtly wrong, so there is deliberately no mock here. // Gated on env so the default `go test ./...` stays offline: // // eval "$(aws configure export-credentials --profile eleven-dev --format env)" && \ // LCHAT_TEST_S3_BUCKET=eleven-dev-home-427880590669 LCHAT_TEST_S3_REGION=eu-west-1 \ // go test ./home/ -run TestS3VaultStore -count=1 -v // // Each run isolates itself under a random test-/ key prefix (and each // subtest store under its own sub-prefix, since the contract expects a fresh // store), and cleanup permanently deletes every version of every object under // the run prefix. import ( "crypto/rand" "encoding/hex" "fmt" "net/url" "os" "testing" ) func TestS3VaultStore(t *testing.T) { bucket := os.Getenv("LCHAT_TEST_S3_BUCKET") if bucket == "" { t.Skip("LCHAT_TEST_S3_BUCKET not set; skipping live S3 contract suite (see file header for how to run)") } region := os.Getenv("LCHAT_TEST_S3_REGION") if region == "" { t.Fatal("LCHAT_TEST_S3_REGION must be set alongside LCHAT_TEST_S3_BUCKET") } var runID [8]byte if _, err := rand.Read(runID[:]); err != nil { t.Fatalf("rand: %v", err) } runPrefix := "test-" + hex.EncodeToString(runID[:]) + "/" root, err := newS3Store(bucket, region, runPrefix, os.Getenv("LCHAT_TEST_S3_ENDPOINT")) if err != nil { t.Fatalf("newS3Store: %v", err) } t.Cleanup(func() { versions, err := root.listVersions(runPrefix) if err != nil { t.Errorf("cleanup list: %v (objects may remain under %s)", err, runPrefix) return } for _, v := range versions { res, err := root.c.do("DELETE", v.key, url.Values{"versionId": {v.versionID}}, nil, nil) if err != nil || (res.status != 204 && res.status != 200) { t.Errorf("cleanup delete %s@%s: status=%v err=%v", v.key, v.versionID, res, err) } } }) // The contract suite expects every newStore call to hand back a FRESH, // empty store — so each gets its own sub-prefix under the run prefix. n := 0 testVaultStore(t, func(t *testing.T) vaultStore { n++ return &s3Store{c: root.c, prefix: fmt.Sprintf("%ss%d/", runPrefix, n)} }) }