mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* filer/store_test: conformance suite for filer stores Entries in and out of buckets, byte-ordered and prefixed listings, key-value records, transactions, bucket tables and the snapshot scan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * filer: run postgres2 and mysql2 through the conformance suite RUN_POSTGRES_TESTS and RUN_MYSQL_TESTS enable them, as RUN_REDIS_TESTS does the Redis stores; each test gets a schema or database of its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * ci: give the go test job Postgres and MySQL services Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * filer/store_test: create the shared fixtures before the subtests The scan and delete-folder-children subtests read the order directory that only the list subtest created, so selecting either one with -run failed on a conforming store. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer/store_test: roll back a transaction an assertion abandons A failed assertion between BeginTransaction and the commit left the transaction open with its locks, and the cleanup's DROP SCHEMA then waited on them until the go test timeout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer/store_test: check limited listings without trimming the result The limit-1 checks sliced the listing to one name, so a store that ignored the limit passed, and one that returned nothing panicked. Allow only the one look-ahead entry the SQL stores return and compare the first name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer/store_test: give the exclusive limit check three eligible names Starting after a%b left only two names under the prefix, so a store that ignored the limit still met the one look-ahead bound. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer/store_test: check that a bucket drop removes nested entries A store that reports CanDropWholeBucket gets no recursive walk from the filer, so its DeleteFolderChildren on the bucket has to remove every descendant. With only a direct child in bkt2, a store that deleted the direct children and kept the table passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package store_test
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
|
|
_ "github.com/jackc/pgx/v5/stdlib"
|
|
"github.com/seaweedfs/seaweedfs/weed/util/pgxutil"
|
|
)
|
|
|
|
// NewPostgresTestDatabase gives the test a schema of its own, dropped after
|
|
// it. PGHOST, PGPORT, PGUSER, PGPASSWORD and PGDATABASE override the defaults.
|
|
func NewPostgresTestDatabase(t *testing.T) pgxutil.DSNOptions {
|
|
if os.Getenv("RUN_POSTGRES_TESTS") != "1" {
|
|
t.Skip("postgres tests are disabled. Start a postgres server and set RUN_POSTGRES_TESTS=1 to enable, it defaults to postgres:postgres@127.0.0.1:5432/postgres.")
|
|
}
|
|
port, _ := strconv.Atoi(envOr("PGPORT", "5432"))
|
|
opts := pgxutil.DSNOptions{
|
|
Hostname: envOr("PGHOST", "127.0.0.1"),
|
|
Port: port,
|
|
User: envOr("PGUSER", "postgres"),
|
|
Password: envOr("PGPASSWORD", "postgres"),
|
|
Database: envOr("PGDATABASE", "postgres"),
|
|
SSLMode: "disable",
|
|
}
|
|
dsn, _ := pgxutil.BuildDSN(opts)
|
|
conn, err := sql.Open("pgx", dsn)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
opts.Schema = fmt.Sprintf("test_%d", time.Now().UnixNano())
|
|
if _, err := conn.Exec(`CREATE SCHEMA "` + opts.Schema + `"`); err != nil {
|
|
conn.Close()
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() {
|
|
conn.Exec(`DROP SCHEMA "` + opts.Schema + `" CASCADE`)
|
|
conn.Close()
|
|
})
|
|
return opts
|
|
}
|
|
|
|
func envOr(name, fallback string) string {
|
|
if v := os.Getenv(name); v != "" {
|
|
return v
|
|
}
|
|
return fallback
|
|
}
|