34 lines
819 B
Go
34 lines
819 B
Go
package imtenant
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|