@@ -4,36 +4,38 @@ import (
44 "context"
55 "database/sql"
66 "errors"
7+ "fmt"
78 "os"
89 "path"
910 "strings"
1011 "testing"
1112 "time"
1213
13- "github.com/go-sql-driver/mysql"
1414 "github.com/letsencrypt/boulder/cmd"
1515 "github.com/letsencrypt/boulder/config"
1616 "github.com/letsencrypt/boulder/test"
1717 "github.com/letsencrypt/boulder/test/vars"
1818)
1919
20+ var dbHost = os .Getenv ("MYSQL_ADDR" )
21+
2022func TestInvalidDSN (t * testing.T ) {
2123 _ , err := DBMapForTest ("invalid" )
2224 test .AssertError (t , err , "DB connect string missing the slash separating the database name" )
2325
24- DSN := "policy:password@tcp(boulder-proxysql:6033 )/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&stringVarThatDoesntExist=%27whoopsidaisies"
26+ DSN := fmt . Sprintf ( "policy:password@tcp(%s )/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&stringVarThatDoesntExist=%% 27whoopsidaisies" , dbHost )
2527 _ , err = DBMapForTest (DSN )
2628 test .AssertError (t , err , "Variable does not exist in curated system var list, but didn't return an error and should have" )
2729
28- DSN = "policy:password@tcp(boulder-proxysql:6033 )/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&concurrent_insert=2"
30+ DSN = fmt . Sprintf ( "policy:password@tcp(%s )/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&concurrent_insert=2" , dbHost )
2931 _ , err = DBMapForTest (DSN )
3032 test .AssertError (t , err , "Variable is unable to be set in the SESSION scope, but was declared" )
3133
32- DSN = "policy:password@tcp(boulder-proxysql:6033 )/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&optimizer_switch=incorrect-quoted-string"
34+ DSN = fmt . Sprintf ( "policy:password@tcp(%s )/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&optimizer_switch=incorrect-quoted-string" , dbHost )
3335 _ , err = DBMapForTest (DSN )
3436 test .AssertError (t , err , "Variable declared with incorrect quoting" )
3537
36- DSN = "policy:password@tcp(boulder-proxysql:6033 )/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&concurrent_insert=%272%27"
38+ DSN = fmt . Sprintf ( "policy:password@tcp(%s )/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&concurrent_insert=%% 272%% 27" , dbHost )
3739 _ , err = DBMapForTest (DSN )
3840 test .AssertError (t , err , "Integer enum declared, but should not have been quoted" )
3941}
@@ -76,7 +78,7 @@ func TestDbSettings(t *testing.T) {
7678 }
7779 dsnFile := path .Join (t .TempDir (), "dbconnect" )
7880 err := os .WriteFile (dsnFile ,
79- []byte ("sa@tcp(boulder-proxysql:6033 )/boulder_sa_integration" ),
81+ []byte (fmt . Sprintf ( "sa@tcp(%s )/boulder_sa_integration" , dbHost ) ),
8082 os .ModeAppend )
8183 test .AssertNotError (t , err , "writing dbconnect file" )
8284
@@ -107,8 +109,8 @@ func TestDbSettings(t *testing.T) {
107109
108110// TODO: Change this to test `newDbMapFromMySQLConfig` instead?
109111func TestNewDbMap (t * testing.T ) {
110- const mysqlConnectURL = "policy:password@tcp(boulder-proxysql:6033 )/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms"
111- const expected = "policy:password@tcp(boulder-proxysql:6033 )/boulder_policy_integration?clientFoundRows=true&parseTime=true&readTimeout=800ms&writeTimeout=800ms&long_query_time=0.640000&max_statement_time=0.760000& sql_mode=%27STRICT_ALL_TABLES%27"
112+ mysqlConnectURL := fmt . Sprintf ( "policy:password@tcp(%s )/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms" , dbHost )
113+ expected := fmt . Sprintf ( "policy:password@tcp(%s )/boulder_policy_integration?clientFoundRows=true&parseTime=true&readTimeout=800ms&writeTimeout=800ms&sql_mode=%% 27STRICT_ALL_TABLES%% 27" , dbHost )
112114 oldSQLOpen := sqlOpen
113115 defer func () {
114116 sqlOpen = oldSQLOpen
@@ -146,27 +148,6 @@ func TestStrictness(t *testing.T) {
146148 }
147149}
148150
149- func TestTimeouts (t * testing.T ) {
150- dbMap , err := DBMapForTest (vars .DBConnSA + "?max_statement_time=1" )
151- if err != nil {
152- t .Fatal ("Error setting up DB:" , err )
153- }
154- // SLEEP is defined to return 1 if it was interrupted, but we want to actually
155- // get an error to simulate what would happen with a slow query. So we wrap
156- // the SLEEP in a subselect.
157- _ , err = dbMap .ExecContext (ctx , `SELECT 1 FROM (SELECT SLEEP(5)) as subselect;` )
158- if err == nil {
159- t .Fatal ("Expected error when running slow query, got none." )
160- }
161-
162- // We expect to get:
163- // Error 1969: Query execution was interrupted (max_statement_time exceeded)
164- // https://mariadb.com/kb/en/mariadb/mariadb-error-codes/
165- if ! strings .Contains (err .Error (), "Error 1969" ) {
166- t .Fatalf ("Got wrong type of error: %s" , err )
167- }
168- }
169-
170151// TestAutoIncrementSchema tests that all of the tables in the boulder_*
171152// databases that have auto_increment columns use BIGINT for the data type. Our
172153// data is too big for INT.
@@ -185,45 +166,3 @@ func TestAutoIncrementSchema(t *testing.T) {
185166 test .AssertNotError (t , err , "unexpected err querying columns" )
186167 test .AssertEquals (t , count , int64 (0 ))
187168}
188-
189- func TestAdjustMySQLConfig (t * testing.T ) {
190- conf := & mysql.Config {}
191- err := adjustMySQLConfig (conf )
192- test .AssertNotError (t , err , "unexpected err setting server variables" )
193- test .AssertDeepEquals (t , conf .Params , map [string ]string {
194- "sql_mode" : "'STRICT_ALL_TABLES'" ,
195- })
196-
197- conf = & mysql.Config {ReadTimeout : 100 * time .Second }
198- err = adjustMySQLConfig (conf )
199- test .AssertNotError (t , err , "unexpected err setting server variables" )
200- test .AssertDeepEquals (t , conf .Params , map [string ]string {
201- "sql_mode" : "'STRICT_ALL_TABLES'" ,
202- "max_statement_time" : "95.000000" ,
203- "long_query_time" : "80.000000" ,
204- })
205-
206- conf = & mysql.Config {
207- ReadTimeout : 100 * time .Second ,
208- Params : map [string ]string {
209- "max_statement_time" : "0" ,
210- },
211- }
212- err = adjustMySQLConfig (conf )
213- test .AssertNotError (t , err , "unexpected err setting server variables" )
214- test .AssertDeepEquals (t , conf .Params , map [string ]string {
215- "sql_mode" : "'STRICT_ALL_TABLES'" ,
216- "long_query_time" : "80.000000" ,
217- })
218-
219- conf = & mysql.Config {
220- Params : map [string ]string {
221- "max_statement_time" : "0" ,
222- },
223- }
224- err = adjustMySQLConfig (conf )
225- test .AssertNotError (t , err , "unexpected err setting server variables" )
226- test .AssertDeepEquals (t , conf .Params , map [string ]string {
227- "sql_mode" : "'STRICT_ALL_TABLES'" ,
228- })
229- }
0 commit comments