chore: seed migration objects batch 5
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package imtenant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNormalizeMySQLTimeOptions(t *testing.T) {
|
||||
link, err := normalizeMySQLTimeOptions("user:pass@tcp(127.0.0.1:3306)/tinode?charset=utf8mb4")
|
||||
if err != nil {
|
||||
t.Fatalf("normalize raw mysql dsn: %v", err)
|
||||
}
|
||||
if !strings.HasPrefix(link, "mysql:user:pass@tcp(127.0.0.1:3306)/tinode?") {
|
||||
t.Fatalf("unexpected normalized link: %s", link)
|
||||
}
|
||||
if !strings.Contains(link, "loc=UTC") || !strings.Contains(link, "parseTime=true") {
|
||||
t.Fatalf("missing required time options: %s", link)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeMySQLTimeOptionsRejectsUnsupportedFormat(t *testing.T) {
|
||||
if _, err := normalizeMySQLTimeOptions("postgres://user:pass@127.0.0.1:5432/tinode"); err == nil {
|
||||
t.Fatal("expected unsupported format error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplaceMySQLDatabaseUsesUTC(t *testing.T) {
|
||||
link, err := replaceMySQLDatabase("mysql:user:pass@tcp(127.0.0.1:3306)/hotgo?loc=Local&parseTime=false&charset=utf8mb4", "tinode")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, expected := range []string{"/tinode?", "loc=UTC", "parseTime=true", "charset=utf8mb4"} {
|
||||
if !strings.Contains(link, expected) {
|
||||
t.Fatalf("link %q does not contain %q", link, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextSnowflakeID(t *testing.T) {
|
||||
first, err := NextSnowflakeID(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
second, err := NextSnowflakeID(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if first <= 0 || second <= first {
|
||||
t.Fatalf("Snowflake IDs are not increasing: %d, %d", first, second)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user