Skip to content

Commit

Permalink
Adds test for auto increment regex validation
Browse files Browse the repository at this point in the history
  • Loading branch information
iamchughmayank committed Dec 26, 2024
1 parent 72d7144 commit 33b2e09
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
18 changes: 18 additions & 0 deletions __fixtures__/dev-env-e2e/fail-autoIncrement-validation.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
DROP TABLE IF EXISTS `wp_a8c_cron_control_jobs`;

CREATE TABLE `wp_a8c_cron_control_jobs` (
`ID` bigint unsigned ,
`timestamp` bigint unsigned NOT NULL,
`action` varchar(255) NOT NULL,
`action_hashed` varchar(32) NOT NULL,
`instance` varchar(32) NOT NULL,
`args` longtext NOT NULL,
`schedule` varchar(255) DEFAULT NULL,
`interval` int unsigned DEFAULT '0',
`status` varchar(32) NOT NULL DEFAULT 'pending',
`created` datetime NOT NULL,
`last_modified` datetime NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `ts_action_instance_status` (`timestamp`,`action`(191),`instance`,`status`),
KEY `status` (`status`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Binary file not shown.
13 changes: 13 additions & 0 deletions __tests__/devenv-e2e/010-import-sql.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ describe( 'vip dev-env import sql', () => {
}
);

it.each( [ 'fail-autoIncrement-validation.sql.gz', 'fail-autoIncrement-validation.sql' ] )(
'should fail if the file fails auto increment validation',
async baseName => {
const file = path.join( __dirname, `../../__fixtures__/dev-env-e2e/${ baseName }` );
const result = await cliTest.spawn(
[ process.argv[ 0 ], vipDevEnvImportSQL, '--slug', slug, file ],
{ env }
);
expect( result.rc ).toBeGreaterThan( 0 );
expect( result.stderr ).toContain( 'SQL Error: AUTO_INCREMENT attribute was not found' );
}
);

it.each( [ 'fail-validation.sql.gz', 'fail-validation.sql' ] )(
'should allow to bypass validation',
async baseName => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/validations/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ const checks: Checks = {
},
autoIncrement: {
matcher: /\s(NOT NULL AUTO_INCREMENT,)/i,
matchHandler: ( _, results ) => ( { text: results[ 1 ] } ),
matchHandler: ( _lineNumber, results ) => ( { text: results[ 1 ] } ),
outputFormatter: requiredCheckFormatter,
results: [],
message: 'AUTO_INCREMENT attribute',
Expand Down

0 comments on commit 33b2e09

Please sign in to comment.