@@ -413,4 +413,76 @@ class { 'mysql::server':
413
413
end
414
414
end
415
415
416
+ describe 'adding privileges to specific table' do
417
+ # Using puppet_apply as a helper
418
+ it 'setup mysql server' do
419
+ pp = <<-EOS
420
+ class { 'mysql::server': override_options => { 'root_password' => 'password' } }
421
+ EOS
422
+
423
+ apply_manifest ( pp , :catch_failures => true )
424
+ end
425
+
426
+ it 'creates grant on missing table will fail' do
427
+ pp = <<-EOS
428
+ mysql_grant { 'test@localhost/grant_spec_db.grant_spec_table':
429
+ user => 'test@localhost',
430
+ privileges => ['SELECT'],
431
+ table => 'grant_spec_db.grant_spec_table',
432
+ }
433
+ EOS
434
+ expect ( apply_manifest ( pp , :expect_failures => true ) . stderr ) . to match ( /Table 'grant_spec_db\. grant_spec_table' doesn't exist/ )
435
+ end
436
+
437
+ it 'checks if table exists before grant' do
438
+ pp = <<-EOS
439
+ if mysql_table_exists('grant_spec_db.grant_spec_table') {
440
+ mysql_grant { 'test@localhost/grant_spec_db.grant_spec_table':
441
+ user => 'test@localhost',
442
+ privileges => 'ALL',
443
+ table => 'grant_spec_db.grant_spec_table',
444
+ }
445
+ }
446
+ EOS
447
+ apply_manifest ( pp , :catch_changes => true )
448
+ end
449
+
450
+ it 'creates table' do
451
+ pp = <<-EOS
452
+ file { '/tmp/grant_spec_table.sql':
453
+ ensure => file,
454
+ content => 'CREATE TABLE grant_spec_table (id int);',
455
+ before => Mysql::Db['grant_spec_db'],
456
+ }
457
+ mysql::db { 'grant_spec_db':
458
+ user => 'root1',
459
+ password => 'password',
460
+ sql => '/tmp/grant_spec_table.sql',
461
+ }
462
+ EOS
463
+
464
+ apply_manifest ( pp , :catch_failures => true )
465
+ end
466
+
467
+ it 'should have the table' do
468
+ expect ( shell ( "mysql -e 'show tables;' grant_spec_db|grep grant_spec_table" ) . exit_code ) . to be_zero
469
+ end
470
+
471
+ it 'checks if table exists before grant' do
472
+ pp = <<-EOS
473
+ if mysql_table_exists('grant_spec_db.grant_spec_table') {
474
+ mysql_grant { 'test@localhost/grant_spec_db.grant_spec_table':
475
+ user => 'test@localhost',
476
+ privileges => ['SELECT'],
477
+ table => 'grant_spec_db.grant_spec_table',
478
+ }
479
+ }
480
+ EOS
481
+ apply_manifest ( pp , :catch_failures => true )
482
+ apply_manifest ( pp , :catch_changes => true )
483
+ end
484
+
485
+
486
+ end
487
+
416
488
end
0 commit comments