github.com/letsencrypt/boulder@v0.20251208.0/sa/sysvars_test.go (about)

     1  package sa
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/letsencrypt/boulder/test"
     7  )
     8  
     9  func TestCheckMariaDBSystemVariables(t *testing.T) {
    10  	type testCase struct {
    11  		key       string
    12  		value     string
    13  		expectErr string
    14  	}
    15  
    16  	for _, tc := range []testCase{
    17  		{"sql_select_limit", "'0.1", "requires a numeric value"},
    18  		{"max_statement_time", "0", ""},
    19  		{"myBabies", "kids_I_tell_ya", "was unexpected"},
    20  		{"sql_mode", "'STRICT_ALL_TABLES", "string is not properly quoted"},
    21  		{"sql_mode", "%27STRICT_ALL_TABLES%27", "string is not properly quoted"},
    22  		{"completion_type", "1", ""},
    23  		{"completion_type", "'2'", "integer enum is quoted, but should not be"},
    24  		{"completion_type", "RELEASE", "string enum is not properly quoted"},
    25  		{"completion_type", "'CHAIN'", ""},
    26  		{"autocommit", "0", ""},
    27  		{"check_constraint_checks", "1", ""},
    28  		{"log_slow_query", "true", ""},
    29  		{"foreign_key_checks", "false", ""},
    30  		{"sql_warnings", "TrUe", ""},
    31  		{"tx_read_only", "FalSe", ""},
    32  		{"sql_notes", "on", ""},
    33  		{"tcp_nodelay", "off", ""},
    34  		{"autocommit", "2", "expected boolean value"},
    35  	} {
    36  		t.Run(tc.key, func(t *testing.T) {
    37  			err := checkMariaDBSystemVariables(tc.key, tc.value)
    38  			if tc.expectErr == "" {
    39  				test.AssertNotError(t, err, "Unexpected error received")
    40  			} else {
    41  				test.AssertError(t, err, "Error expected, but not found")
    42  				test.AssertContains(t, err.Error(), tc.expectErr)
    43  			}
    44  		})
    45  	}
    46  }