File tree 2 files changed +9
-1
lines changed
lib/puppet/provider/mysql_user
spec/unit/puppet/provider/mysql_user 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,9 @@ def create
96
96
97
97
def destroy
98
98
merged_name = @resource [ :name ] . sub ( '@' , "'@'" )
99
- self . class . mysql_caller ( "DROP USER '#{ merged_name } '" , 'system' )
99
+ if_exists = ( Puppet ::Util ::Package . versioncmp ( mysqld_version , '5.7' ) >= 0 ) ? 'IF EXISTS ' : ''
100
+
101
+ self . class . mysql_caller ( "DROP USER #{ if_exists } '#{ merged_name } '" , 'system' )
100
102
101
103
@property_hash . clear
102
104
exists? ? ( return false ) : ( return true )
Original file line number Diff line number Diff line change 183
183
provider . expects ( :exists? ) . returns ( false )
184
184
expect ( provider . destroy ) . to be_truthy
185
185
end
186
+ it 'removes a user using IF EXISTS' do
187
+ provider . class . instance_variable_set ( :@mysqld_version_string , '5.7.1' )
188
+
189
+ provider . class . expects ( :mysql_caller ) . with ( "DROP USER IF EXISTS 'joe'@'localhost'" , 'system' )
190
+ expect ( provider . destroy ) . to be_truthy
191
+ end
186
192
end
187
193
188
194
describe 'exists?' do
You can’t perform that action at this time.
0 commit comments