Files
past-go/past-go/internal/config/config_test.go
T
2026-10-07 09:28:43 +08:00

28 lines
615 B
Go

package config
import (
"strings"
"testing"
"github.com/go-sql-driver/mysql"
)
func TestDSNSetsShanghaiOffsetForEveryConnection(t *testing.T) {
c := &Config{}
c.DB.Host = "127.0.0.1"
c.DB.Port = 3306
c.DB.Name = "past"
c.DB.User = "past"
got := c.DSN()
if !strings.Contains(got, "time_zone=%27%2B08%3A00%27") {
t.Fatalf("DSN does not set MySQL session time zone: %s", got)
}
parsed, err := mysql.ParseDSN(got)
if err != nil {
t.Fatalf("invalid DSN: %v", err)
}
if parsed.Params["time_zone"] != "'+08:00'" {
t.Fatalf("unexpected decoded MySQL time_zone: %q", parsed.Params["time_zone"])
}
}