Skip to content

Commit

Permalink
feat: autodetect go.mod file
Browse files Browse the repository at this point in the history
  • Loading branch information
lwywoo committed Jul 2, 2019
1 parent 7eb639a commit bb404ad
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions help/file.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ looking for files in following order:
Pipfile
requirements.txt
Gopkg.lock
go.mod
vendor/vendor.json
project.assets.json
packages.config
Expand Down
1 change: 1 addition & 0 deletions src/lib/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const DETECTABLE_FILES: string[] = [
'Pipfile',
'requirements.txt',
'Gopkg.lock',
'go.mod',
'vendor/vendor.json',
'obj/project.assets.json',
'project.assets.json',
Expand Down
23 changes: 18 additions & 5 deletions test/acceptance/cli.acceptance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1416,23 +1416,36 @@ test('`test golang-gomodules --file=go.mod`', async (t) => {
}], 'calls golang plugin');
});

test('`test golang-app` does not auto-detect golang-gomodules', async (t) => {
test('`test golang-app` auto-detects golang-gomodules', async (t) => {
chdirWorkspaces();
const plugin = {
async inspect() {
return { package: {}, plugin: { name: 'testplugin', runtime: 'testruntime' } };
return {package: {}, plugin: {name: 'testplugin', runtime: 'testruntime'}};
},
};
sinon.spy(plugin, 'inspect');
const spyPlugin = sinon.spy(plugin, 'inspect');

const loadPlugin = sinon.stub(plugins, 'loadPlugin');
t.teardown(loadPlugin.restore);
loadPlugin
.withArgs('gomodules')
.returns(plugin);

t.rejects(cli.test('golang-gomodules'), /Could not detect supported target files/,
'NoSupportedManifestsFoundError error is shown');
await cli.test('golang-gomodules');
const req = server.popRequest();
t.equal(req.method, 'POST', 'makes POST request');
t.match(req.url, '/test-dep-graph', 'posts to correct url');
t.equal(req.body.depGraph.pkgManager.name, 'gomodules');
t.equal(req.body.targetFile, 'go.mod', 'specifies target');
t.same(spyPlugin.getCall(0).args,
['golang-gomodules', 'go.mod', {
args: null,
file: 'go.mod',
org: null,
packageManager: 'gomodules',
path: 'golang-gomodules',
showVulnPaths: true,
}], 'calls golang-gomodules plugin');
});

test('`test golang-app --file=Gopkg.lock`', async (t) => {
Expand Down

0 comments on commit bb404ad

Please sign in to comment.