Files
seaweedfs/weed/filer/postgres/postgres_flat_sql_gen_test.go
T
Chris LuandClaude Opus 5.5 cba6549067 filer/postgres: SQL generator keyed by the full path
Rows have path as their primary key; a (directory, name) unique
constraint serves the directory listings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK
2026-12-01 16:38:39 -08:00

43 lines
1.5 KiB
Go

package postgres
import (
"strings"
"testing"
"github.com/seaweedfs/seaweedfs/weed/filer/abstract_sql"
)
func TestFlatPath(t *testing.T) {
for _, c := range []struct{ dir, name, want string }{
{"/", "", "/"},
{"/", "a.txt", "/a.txt"},
{"/dir/sub", "a.txt", "/dir/sub/a.txt"},
{"", "", ""},
} {
if got := flatPath(abstract_sql.EntryRowKey(c.dir, c.name)); got != c.want {
t.Errorf("flatPath(%q, %q) = %q, want %q", c.dir, c.name, got, c.want)
}
}
}
func TestFlatStatementsAddressRowsByPath(t *testing.T) {
gen := &SqlGenPostgresFlat{SqlGenPostgres{UpsertQueryTemplate: DefaultFlatUpsertQuery}}
key := abstract_sql.EntryRowKey("/dir", "a.txt")
insert, args := gen.GetSqlInsert("filemeta", key, []byte("m"))
if !strings.Contains(insert, "ON CONFLICT (path)") || args[0] != "/dir/a.txt" || args[1] != "/dir" || args[2] != "a.txt" {
t.Fatalf("insert %s %v", insert, args)
}
update, args := gen.GetSqlUpdate("filemeta", key, []byte("m"))
if !strings.Contains(update, "WHERE path=$1") || args[0] != "/dir/a.txt" {
t.Fatalf("update %s %v", update, args)
}
list, args := gen.GetSqlListExclusive("filemeta", "/dir", "", "%", 10)
if !strings.Contains(list, "WHERE directory=$1") || args[0] != "/dir" {
t.Fatalf("list %s %v", list, args)
}
gen.ForceBinaryCollation = true
if list, _ = gen.GetSqlListInclusive("filemeta", "/dir", "", "%", 10); !strings.Contains(list, `ORDER BY name COLLATE "C"`) {
t.Fatalf("list without a byte-ordered column: %s", list)
}
}