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) } }