visedriver/storage/parse_test.go

58 lines
1.3 KiB
Go
Raw Normal View History

2025-01-04 10:37:12 +01:00
package storage
import (
"testing"
)
func TestParseConnStr(t *testing.T) {
2025-01-19 10:04:37 +01:00
v, err := ToConnData("postgres://foo:bar@localhost:5432/baz")
2025-01-04 10:37:12 +01:00
if err != nil {
t.Fatal(err)
}
2025-01-19 10:04:37 +01:00
if v.DbType() != DBTYPE_POSTGRES {
t.Fatalf("expected type %v, got %v", DBTYPE_POSTGRES, v.DbType())
}
v, err = ToConnData("gdbm:///foo/bar")
2025-01-04 10:37:12 +01:00
if err != nil {
t.Fatal(err)
}
2025-01-19 10:04:37 +01:00
if v.DbType() != DBTYPE_GDBM {
t.Fatalf("expected type %v, got %v", DBTYPE_GDBM, v.DbType())
}
v, err = ToConnData("/foo/bar")
if err != nil {
t.Fatal(err)
2025-01-04 10:37:12 +01:00
}
2025-01-19 10:04:37 +01:00
if v.DbType() != DBTYPE_FS {
t.Fatalf("expected type %v, got %v", DBTYPE_FS, v.DbType())
}
v, err = ToConnData("/foo/bar/")
if err != nil {
t.Fatal(err)
}
if v.DbType() != DBTYPE_FS {
t.Fatalf("expected type %v, got %v", DBTYPE_FS, v.DbType())
2025-01-04 10:37:12 +01:00
}
2025-01-19 10:04:37 +01:00
v, err = ToConnData("foo/bar")
if err != nil {
t.Fatal(err)
}
if v.DbType() != DBTYPE_FS {
t.Fatalf("expected type %v, got %v", DBTYPE_FS, v.DbType())
}
v, err = ToConnData("")
if err != nil {
t.Fatal(err)
}
if v.DbType() != DBTYPE_MEM {
t.Fatalf("expected type %v, got %v", DBTYPE_MEM, v.DbType())
}
v, err = ToConnData("http://foo/bar")
2025-01-04 10:37:12 +01:00
if err == nil {
t.Fatalf("expected error")
}
2025-01-19 10:04:37 +01:00
if v.DbType() != DBTYPE_NONE {
t.Fatalf("expected type %v, got %v", DBTYPE_NONE, v.DbType())
}
2025-01-04 10:37:12 +01:00
}