Skip to content

Commit

Permalink
Merge pull request #308 from snyk-tech-services/test/orgs-create-exit…
Browse files Browse the repository at this point in the history
…-codes

test: assert current exit code 0 for orgs:create errors
  • Loading branch information
lili2311 authored Mar 2, 2022
2 parents 3cc0dba + a37d2e0 commit db31289
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 61 deletions.
30 changes: 0 additions & 30 deletions test/system/__snapshots__/help.test.ts.snap

This file was deleted.

19 changes: 0 additions & 19 deletions test/system/__snapshots__/orgs:create.test.ts.snap

This file was deleted.

29 changes: 28 additions & 1 deletion test/system/help.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,34 @@ describe('`snyk-api-import help <...>`', () => {
}
expect(err).toBeNull();
expect(stderr).toEqual('');
expect(stdout.trim()).toMatchSnapshot();
expect(stdout.trim()).toMatchInlineSnapshot(`
"index.js
Kick off API powered import
Commands:
index.js import Kick off API powered import [default] [aliases: i]
index.js import:data Generate data required for targets to be imported via
API to create Snyk projects.
index.js list:imported List all targets imported in Snyk for a given group &
source type. An analysis is performed on all current
organizations and their projects to generate this. The
generated file can be used to skip previously imported
targets when running the \`import\` command
index.js orgs:create Create the organizations in Snyk based on data file
generated with \`orgs:data\` command. Output generates
key data for created and existing organizations for
use to generate project import data.
index.js orgs:data Generate data required for Orgs to be created via API
by mirroring a given source.
Options:
--version Show version number [boolean]
--help Show help [boolean]
--file Path to json file that contains the targets to be imported"
`);
}).on('exit', (code) => {
expect(code).toEqual(0);
done();
Expand Down
46 changes: 35 additions & 11 deletions test/system/orgs:create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,25 @@ describe('`snyk-api-import help <...>`', () => {
throw err;
}
expect(err).toBeNull();
expect(stdout.trim()).toMatchSnapshot();
expect(stdout.trim()).toMatchInlineSnapshot(`
"index.js orgs:create
Create the organizations in Snyk based on data file generated with \`orgs:data\`
command. Output generates key data for created and existing organizations for
use to generate project import data.
Options:
--version Show version number [boolean]
--help Show help [boolean]
--file Path to data file generated with \`orgs:data\`
command [required]
--noDuplicateNames Skip creating an organization if the given name
is already taken within the Group.
--includeExistingOrgsInOutput Log existing organization information as well
as newly created [default: true]"
`);
}).on('exit', (code) => {
expect(code).toEqual(0);
done();
});
});
Expand Down Expand Up @@ -53,12 +71,14 @@ describe('`snyk-api-import help <...>`', () => {
path.resolve(logPath, `abc.${FAILED_ORG_LOG_NAME}`),
'utf8',
);
expect(file).toContain('Please provide the group public id');
expect(file).toContain('Failed to create org');
deleteFiles([path.resolve(logPath, `abc.${FAILED_ORG_LOG_NAME}`)]);
done();
},
);
}, 400000);
).on('exit', (code) => {
expect(code).toEqual(0);
done();
});
}, 20000);

it('Fails to create an org as expected for non existing group ID `abc` file not in the same location as logs', (done) => {
const pathToBadJson = path.resolve(
Expand Down Expand Up @@ -91,12 +111,14 @@ describe('`snyk-api-import help <...>`', () => {
path.resolve(logPath, `abc.${FAILED_ORG_LOG_NAME}`),
'utf8',
);
expect(file).toContain('Please provide the group public id');
expect(file).toContain('Failed to create org');
deleteFiles([path.resolve(logPath, `abc.${FAILED_ORG_LOG_NAME}`)]);
done();
},
);
}, 400000);
).on('exit', (code) => {
expect(code).toEqual(0);
done();
});
}, 20000);

it('Fails to create orgs in --noDuplicateNames mode when org already exists ', (done) => {
const pathToBadJson = path.resolve(
Expand Down Expand Up @@ -133,8 +155,10 @@ describe('`snyk-api-import help <...>`', () => {
deleteFiles([
path.resolve(logPath, `${GROUP_ID}.${FAILED_ORG_LOG_NAME}`),
]);
done();
},
);
).on('exit', (code) => {
expect(code).toEqual(0);
done();
});
}, 20000);
});

0 comments on commit db31289

Please sign in to comment.