(t *testing.T)
| 102 | } |
| 103 | |
| 104 | func TestDatabaseDSNUsesCustomValues(t *testing.T) { |
| 105 | setDBEnv(t, map[string]string{ |
| 106 | "DB_USER": "app", |
| 107 | "DB_PASSWORD": "secret", |
| 108 | "DB_HOST": "mysql.local", |
| 109 | "DB_PORT": "3307", |
| 110 | "DB_NAME": "singo_test", |
| 111 | "DB_CHARSET": "utf8mb4", |
| 112 | "DB_PARSE_TIME": "true", |
| 113 | "DB_LOC": "Asia/Shanghai", |
| 114 | }) |
| 115 | |
| 116 | dsn, err := DatabaseDSN() |
| 117 | if err != nil { |
| 118 | t.Fatalf("expected no error, got %v", err) |
| 119 | } |
| 120 | |
| 121 | config := parseConfig(t, dsn) |
| 122 | if config.User != "app" { |
| 123 | t.Fatalf("expected user app, got %q", config.User) |
| 124 | } |
| 125 | if config.Passwd != "secret" { |
| 126 | t.Fatalf("expected password secret, got %q", config.Passwd) |
| 127 | } |
| 128 | if config.Addr != "mysql.local:3307" { |
| 129 | t.Fatalf("expected address mysql.local:3307, got %q", config.Addr) |
| 130 | } |
| 131 | if config.DBName != "singo_test" { |
| 132 | t.Fatalf("expected database singo_test, got %q", config.DBName) |
| 133 | } |
| 134 | if charset := dsnQuery(t, dsn).Get("charset"); charset != "utf8mb4" { |
| 135 | t.Fatalf("expected charset utf8mb4, got %q", charset) |
| 136 | } |
| 137 | if !config.ParseTime { |
| 138 | t.Fatal("expected parseTime to be true") |
| 139 | } |
| 140 | if config.Loc.String() != "Asia/Shanghai" { |
| 141 | t.Fatalf("expected location Asia/Shanghai, got %q", config.Loc.String()) |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | func TestDatabaseDSNAllowsSpecialCharactersInPassword(t *testing.T) { |
| 146 | setDBEnv(t, map[string]string{ |
nothing calls this directly
no test coverage detected