Repository navigation
Expand file tree
/
Copy pathMySQLTestCase.cls
More file actions
149 lines (114 loc) · 4.44 KB
/
Copy pathMySQLTestCase.cls
File metadata and controls
149 lines (114 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"Filed out from Dolphin Smalltalk"!
TestCase subclass: #MySQLTestCase
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
classInstanceVariableNames: ''!
MySQLTestCase guid: (GUID fromString: '{db3d0787-590e-4026-a247-03c1c5e0e997}')!
MySQLTestCase comment: ''!
!MySQLTestCase categoriesForClass!MySQL-Core-Tests-Integration-Base! !
!MySQLTestCase methodsFor!
_createCachingSha2User: aBlock
"Private - Create a user who requires caching_sha2_password authentication.
aBlock is evaluated to carry out further tests whilst the user is extant (evaluated with connection spec for the user).
Not supported on MariaDB"
| connection resp connectionSpec |
connection := MySQLDriver new.
connection connect: self driverSpec.
connection isMariaDB ifTrue: [^self].
connectionSpec := self driverSpec.
connectionSpec
database: nil;
user: (connectionSpec user, '_ssl').
resp := connection query: 'CREATE USER ''', connectionSpec user, '''@''%''IDENTIFIED WITH caching_sha2_password BY ''', connectionSpec password , ''';'.
resp isOkay ifFalse: [connection disconnect. self error: 'Could not create caching_sha2_password user'].
[aBlock value: connectionSpec] ensure:
[resp := connection query: 'DROP USER ''', connectionSpec user, '''@''%'''.
resp isOkay ifFalse: [self error: 'Could not drop caching_sha2_password user'].
connection disconnect]!
_createNativePasswordUser: aBlock
"Private - Create a user who requires mysql_native_password authentication.
aBlock is evaluated to carry out further tests whilst the user is extant (evaluated with connection spec for the user).
Not supported on newer MySQL installations"
| connection resp connectionSpec |
connection := MySQLDriver new.
connection connect: self driverSpec.
(connection isMariaDB not and: [connection majorVersion > 8]) ifTrue: [^self].
connectionSpec := self driverSpec.
connectionSpec
database: nil;
user: (connectionSpec user, '_np').
resp := connection query: 'CREATE USER ''', connectionSpec user, '''@''%''IDENTIFIED WITH mysql_native_password BY ''', connectionSpec password , ''';'.
resp isOkay ifFalse: [connection disconnect. self error: 'Could not create mysql_native_password user'].
[aBlock value: connectionSpec] ensure:
[resp := connection query: 'DROP USER ''', connectionSpec user, '''@''%'''.
resp isOkay ifFalse: [self error: 'Could not drop mysql_native_password user'].
connection disconnect]!
cleanUpFixtureData self class resourceClass current clearTestTables !
configureNotStrict: connection "Change the sql_mode for the current session test (in case of strict mode enabled)" connection query: 'SET SESSION sql_mode = ''NO_ENGINE_SUBSTITUTION'';'.!
connection ^ self testConnection !
driverSpec ^ self class resourceClass driverSpecWithDb !
loadOneFixture: fixtureName | fixtureSel fixtureStmtList conn resp | fixtureSel := 'fixture', fixtureName capitalized. fixtureStmtList := self class fixtureClass perform: fixtureSel asSymbol. fixtureStmtList do: [:stmt | conn := self resourceConnection. resp := conn query: stmt. resp isError ifTrue: [self error: 'Error loading fixture from ', fixtureSel]] !
resourceConnection ^ self class resourceClass current resourceConnection !
specForTest ^ self class resourceClass current specForTest!
tearDown self cleanUpFixtureData. super tearDown !
testConnection ^ self class resourceClass current testConnection !
withFixtures: fixtureNameList do: testBlock fixtureNameList do: [:each | self loadOneFixture: each]. testBlock value: self resourceConnection ! !
!MySQLTestCase categoriesForMethods!
_createCachingSha2User:!private!tests! !
_createNativePasswordUser:!private!tests! !
cleanUpFixtureData!cleanup!public! !
configureNotStrict:!accessing!public! !
connection!accessing!public! !
driverSpec!accessing!public! !
loadOneFixture:!accessing!public! !
resourceConnection!accessing!public! !
specForTest!accessing!public! !
tearDown!public!running! !
testConnection!public!tests! !
withFixtures:do:!accessing!public! !
!
!MySQLTestCase class methodsFor!
fixtureClass "Override this in order to offer test specific fixture class" ^ MySQLTestFixture !
resourceClass ^ MySQLTestResource!
resources ^ Set new add: self resourceClass; yourself! !
!MySQLTestCase class categoriesForMethods!
fixtureClass!private! !
resourceClass!private! !
resources!private! !
!