-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from snyk/fix/add-test-helper-to-read-fixtures
fix: add helper to read test fixtures
- Loading branch information
Showing
25 changed files
with
373 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
/** | ||
* Asynchronous fs.readFile. | ||
*/ | ||
export async function readFile(path): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
fs.readFile(path, 'utf8', function(err, data) { | ||
if (err) { | ||
reject(err); | ||
} | ||
resolve(data); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Read file and return contents parsed to JSON object. | ||
* | ||
* @param filePath path to file | ||
*/ | ||
export async function readJSON(filePath: string) { | ||
try { | ||
const contents = await readFile(filePath); | ||
return JSON.parse(contents); | ||
} catch (err) { | ||
throw new Error( | ||
'Could not parse json file ' + filePath + '. ' + err.message, | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Read test fixture file. | ||
* | ||
* @param fixturePath path relative to test fixtures directory. | ||
*/ | ||
export async function readFixture(fixturePath: string) { | ||
const filePath = path.join(__dirname, 'fixtures', fixturePath); | ||
return await readFile(filePath); | ||
} | ||
|
||
/** | ||
* Read test fixture file and parse to JSON. | ||
* | ||
* @param fixturePath path relative to test fixtures directory. | ||
*/ | ||
export async function readFixtureJSON(fixturePath: string) { | ||
const filePath = path.join(__dirname, 'fixtures', fixturePath); | ||
return await readJSON(filePath); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions
23
tests/fixtures/jars/fixtures.jars:spring-core-5.1.8.RELEASE.jar.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"plugin": { "name": "bundled:maven", "runtime": "unknown" }, | ||
"package": { | ||
"name": "fixtures.jars:spring-core-5.1.8.RELEASE.jar", | ||
"version": "1.0.0-SNAPSHOT", | ||
"dependencies": { | ||
"org.springframework:spring-core": { | ||
"version": "5.1.8.RELEASE", | ||
"name": "org.springframework:spring-core", | ||
"dependencies": { | ||
"org.springframework:spring-jcl": { | ||
"version": "5.1.8.RELEASE", | ||
"name": "org.springframework:spring-jcl", | ||
"dependencies": {}, | ||
"labels": { "scope": "compile" } | ||
} | ||
}, | ||
"labels": { "scope": "compile" } | ||
} | ||
}, | ||
"packageFormatVersion": "mvn:0.0.1" | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/fixtures/jars/jars:spring-core-5.1.8.RELEASE.jar.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"plugin": { "name": "bundled:maven", "runtime": "unknown" }, | ||
"package": { | ||
"name": "jars:spring-core-5.1.8.RELEASE.jar", | ||
"version": "1.0.0-SNAPSHOT", | ||
"dependencies": { | ||
"org.springframework:spring-core": { | ||
"version": "5.1.8.RELEASE", | ||
"name": "org.springframework:spring-core", | ||
"dependencies": { | ||
"org.springframework:spring-jcl": { | ||
"version": "5.1.8.RELEASE", | ||
"name": "org.springframework:spring-jcl", | ||
"dependencies": {}, | ||
"labels": { "scope": "compile" } | ||
} | ||
}, | ||
"labels": { "scope": "compile" } | ||
} | ||
}, | ||
"packageFormatVersion": "mvn:0.0.1" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"plugin": { "name": "bundled:maven", "runtime": "unknown" }, | ||
"package": { | ||
"name": "io.snyk.example:test-project", | ||
"version": "1.0-SNAPSHOT", | ||
"dependencies": { | ||
"axis:axis": { | ||
"version": "1.4", | ||
"name": "axis:axis", | ||
"dependencies": { | ||
"org.apache.axis:axis-jaxrpc": { | ||
"version": "1.4", | ||
"name": "org.apache.axis:axis-jaxrpc", | ||
"dependencies": {}, | ||
"labels": { "scope": "compile" } | ||
}, | ||
"org.apache.axis:axis-saaj": { | ||
"version": "1.4", | ||
"name": "org.apache.axis:axis-saaj", | ||
"dependencies": {}, | ||
"labels": { "scope": "compile" } | ||
}, | ||
"axis:axis-wsdl4j": { | ||
"version": "1.5.1", | ||
"name": "axis:axis-wsdl4j", | ||
"dependencies": {}, | ||
"labels": { "scope": "runtime" } | ||
}, | ||
"commons-logging:commons-logging": { | ||
"version": "1.0.4", | ||
"name": "commons-logging:commons-logging", | ||
"dependencies": {}, | ||
"labels": { "scope": "runtime" } | ||
}, | ||
"commons-discovery:commons-discovery": { | ||
"version": "0.2", | ||
"name": "commons-discovery:commons-discovery", | ||
"dependencies": {}, | ||
"labels": { "scope": "runtime" } | ||
} | ||
}, | ||
"labels": { "scope": "compile" } | ||
} | ||
}, | ||
"packageFormatVersion": "mvn:0.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"plugin": { "name": "bundled:maven", "runtime": "unknown" }, | ||
"package": { | ||
"name": "io.snyk.example:test-project", | ||
"version": "1.0-SNAPSHOT", | ||
"dependencies": { | ||
"axis:axis": { | ||
"version": "1.4", | ||
"name": "axis:axis", | ||
"dependencies": { | ||
"org.apache.axis:axis-jaxrpc": { | ||
"version": "1.4", | ||
"name": "org.apache.axis:axis-jaxrpc", | ||
"dependencies": {}, | ||
"labels": { "scope": "compile" } | ||
}, | ||
"org.apache.axis:axis-saaj": { | ||
"version": "1.4", | ||
"name": "org.apache.axis:axis-saaj", | ||
"dependencies": {}, | ||
"labels": { "scope": "compile" } | ||
}, | ||
"axis:axis-wsdl4j": { | ||
"version": "1.5.1", | ||
"name": "axis:axis-wsdl4j", | ||
"dependencies": {}, | ||
"labels": { "scope": "runtime" } | ||
}, | ||
"commons-logging:commons-logging": { | ||
"version": "1.0.4", | ||
"name": "commons-logging:commons-logging", | ||
"dependencies": {}, | ||
"labels": { "scope": "runtime" } | ||
}, | ||
"commons-discovery:commons-discovery": { | ||
"version": "0.2", | ||
"name": "commons-discovery:commons-discovery", | ||
"dependencies": {}, | ||
"labels": { "scope": "runtime" } | ||
} | ||
}, | ||
"labels": { "scope": "compile" } | ||
}, | ||
"junit:junit": { | ||
"version": "4.10", | ||
"name": "junit:junit", | ||
"dependencies": { | ||
"org.hamcrest:hamcrest-core": { | ||
"version": "1.1", | ||
"name": "org.hamcrest:hamcrest-core", | ||
"dependencies": {}, | ||
"labels": { "scope": "test" } | ||
} | ||
}, | ||
"labels": { "scope": "test" } | ||
} | ||
}, | ||
"packageFormatVersion": "mvn:0.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"plugin": { "name": "bundled:maven", "runtime": "unknown" }, | ||
"package": { | ||
"name": "io.snyk.example:test-project", | ||
"version": "1.0-SNAPSHOT", | ||
"dependencies": { | ||
"axis:axis": { | ||
"version": "1.4", | ||
"name": "axis:axis", | ||
"dependencies": { | ||
"org.apache.axis:axis-jaxrpc": { | ||
"version": "1.4", | ||
"name": "org.apache.axis:axis-jaxrpc", | ||
"dependencies": {}, | ||
"labels": { "scope": "compile" } | ||
}, | ||
"org.apache.axis:axis-saaj": { | ||
"version": "1.4", | ||
"name": "org.apache.axis:axis-saaj", | ||
"dependencies": {}, | ||
"labels": { "scope": "compile" } | ||
}, | ||
"axis:axis-wsdl4j": { | ||
"version": "1.5.1", | ||
"name": "axis:axis-wsdl4j", | ||
"dependencies": {}, | ||
"labels": { "scope": "runtime" } | ||
}, | ||
"commons-logging:commons-logging": { | ||
"version": "1.0.4", | ||
"name": "commons-logging:commons-logging", | ||
"dependencies": {}, | ||
"labels": { "scope": "runtime" } | ||
}, | ||
"commons-discovery:commons-discovery": { | ||
"version": "0.2", | ||
"name": "commons-discovery:commons-discovery", | ||
"dependencies": {}, | ||
"labels": { "scope": "runtime" } | ||
} | ||
}, | ||
"labels": { "scope": "compile" } | ||
} | ||
}, | ||
"packageFormatVersion": "mvn:0.0.1" | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,22 @@ | ||
import * as test from 'tap-only'; | ||
import { isJar } from '../../lib/jar'; | ||
|
||
test('detects jar files', (t) => { | ||
const jarPaths = [ | ||
test('isJar', async (t) => { | ||
[ | ||
'mvn-app-1.0-SNAPSHOT.jar', | ||
'mvn-app-1.0-SNAPSHOT.war', | ||
'mvn-app-1.0-SNAPSHOT.zip', | ||
]; | ||
for (const path of jarPaths) { | ||
t.ok(isJar(path), path); | ||
} | ||
t.end(); | ||
}); | ||
'path/to/mvn-app-1.0-SNAPSHOT.jar', | ||
'path/to/mvn-app-1.0-SNAPSHOT.war', | ||
'path/to/mvn-app-1.0-SNAPSHOT.zip', | ||
].forEach((i) => t.ok(isJar(i), 'should be true for ' + i)); | ||
|
||
test('ignores non jar files', (t) => { | ||
const jarPaths = [ | ||
[ | ||
'mvn-app-1.0-SNAPSHOTjar', | ||
'mvn-app-1.0-SNAPSHOT.txt', | ||
'mvn-app-1.0-SNAPSHOT.jzip', | ||
]; | ||
for (const path of jarPaths) { | ||
t.ok(!isJar(path), path); | ||
} | ||
t.end(); | ||
'path/to/jar/mvn-app-1.0-SNAPSHOTjar', | ||
'path/to/war/mvn-app-1.0-SNAPSHOTwar', | ||
'path/to/zip/mvn-app-1.0-SNAPSHOTzip', | ||
].forEach((i) => t.notOk(isJar(i), 'should be false for ' + i)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
import * as test from 'tap-only'; | ||
import * as plugin from '../../lib'; | ||
|
||
test('check build args with array', (t) => { | ||
test('buildArgs with array', async (t) => { | ||
const result = plugin.buildArgs(null, null, ['-Paxis', '-Pjaxen']); | ||
t.deepEquals(result, [ | ||
'dependency:tree', | ||
'-DoutputType=dot', | ||
'-Paxis', | ||
'-Pjaxen', | ||
]); | ||
t.end(); | ||
t.same( | ||
result, | ||
['dependency:tree', '-DoutputType=dot', '-Paxis', '-Pjaxen'], | ||
'should return expected array', | ||
); | ||
}); | ||
|
||
test('check build args with string', (t) => { | ||
test('buildArgs with string', async (t) => { | ||
const result = plugin.buildArgs(null, null, '-Paxis -Pjaxen'); | ||
t.deepEqual(result, [ | ||
'dependency:tree', | ||
'-DoutputType=dot', | ||
'-Paxis -Pjaxen', | ||
]); | ||
t.end(); | ||
t.same( | ||
result, | ||
['dependency:tree', '-DoutputType=dot', '-Paxis -Pjaxen'], | ||
'should return expected array', | ||
); | ||
}); |
Oops, something went wrong.