Skip to content

Commit 85e4c52

Browse files
committed
test: make sure absolute paths work
1 parent 820dcce commit 85e4c52

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed

__snapshots__/main_test.snap

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,3 +1255,98 @@ ignore:
12551255
- GHSA-rp65-9cf3-cjxr
12561256

12571257
---
1258+
1259+
[TestRun_Lockfile_AbsolutePath/#02 - 1]
1260+
Loaded the following OSV databases:
1261+
1262+
/home/jones/workspace/projects-personal/osv-detector/testdata/locks-empty/Gemfile.lock: found 0 packages
1263+
1264+
no known vulnerabilities found
1265+
1266+
/home/jones/workspace/projects-personal/osv-detector/testdata/locks-empty/composer.lock: found 0 packages
1267+
1268+
no known vulnerabilities found
1269+
1270+
/home/jones/workspace/projects-personal/osv-detector/testdata/locks-empty/yarn.lock: found 0 packages
1271+
1272+
no known vulnerabilities found
1273+
1274+
---
1275+
1276+
[TestRun_Lockfile_AbsolutePath/#02 - 2]
1277+
1278+
---
1279+
1280+
[TestRun_Lockfile_AbsolutePath/#00 - 1]
1281+
Loaded the following OSV databases:
1282+
npm (%% vulnerabilities, including withdrawn - last updated %%)
1283+
1284+
/home/jones/workspace/projects-personal/osv-detector/testdata/locks-one/yarn.lock: found 1 package
1285+
Using db npm (%% vulnerabilities, including withdrawn - last updated %%)
1286+
1287+
no known vulnerabilities found
1288+
1289+
---
1290+
1291+
[TestRun_Lockfile_AbsolutePath/#00 - 2]
1292+
1293+
---
1294+
1295+
[TestRun_Lockfile_AbsolutePath/#04 - 1]
1296+
{"results":[{"filePath":"/home/jones/workspace/projects-personal/osv-detector/testdata/locks-one/yarn.lock","parsedAs":"yarn.lock","packages":[{"name":"balanced-match","version":"1.0.2","ecosystem":"npm","compareAs":"npm","vulnerabilities":[],"ignored":[]}]}]}
1297+
---
1298+
1299+
[TestRun_Lockfile_AbsolutePath/#04 - 2]
1300+
Loaded the following OSV databases:
1301+
npm (%% vulnerabilities, including withdrawn - last updated %%)
1302+
1303+
/home/jones/workspace/projects-personal/osv-detector/testdata/locks-one/yarn.lock: found 1 package
1304+
Using db npm (%% vulnerabilities, including withdrawn - last updated %%)
1305+
1306+
1307+
---
1308+
1309+
[TestRun_Lockfile_AbsolutePath/#03 - 1]
1310+
Loaded the following OSV databases:
1311+
npm (%% vulnerabilities, including withdrawn - last updated %%)
1312+
1313+
/home/jones/workspace/projects-personal/osv-detector/testdata/locks-insecure/my-package-lock.json: found 1 package
1314+
Using db npm (%% vulnerabilities, including withdrawn - last updated %%)
1315+
1316+
ansi-html@0.0.1 is affected by the following vulnerabilities:
1317+
GHSA-whgm-jr23-g3j9: Uncontrolled Resource Consumption in ansi-html (https://github.com/advisories/GHSA-whgm-jr23-g3j9)
1318+
1319+
1 known vulnerability found in /home/jones/workspace/projects-personal/osv-detector/testdata/locks-insecure/my-package-lock.json
1320+
1321+
---
1322+
1323+
[TestRun_Lockfile_AbsolutePath/#03 - 2]
1324+
1325+
---
1326+
1327+
[TestRun_Lockfile_AbsolutePath/#01 - 1]
1328+
Loaded the following OSV databases:
1329+
RubyGems (%% vulnerabilities, including withdrawn - last updated %%)
1330+
Packagist (%% vulnerabilities, including withdrawn - last updated %%)
1331+
npm (%% vulnerabilities, including withdrawn - last updated %%)
1332+
1333+
/home/jones/workspace/projects-personal/osv-detector/testdata/locks-many/Gemfile.lock: found 1 package
1334+
Using db RubyGems (%% vulnerabilities, including withdrawn - last updated %%)
1335+
1336+
no known vulnerabilities found
1337+
1338+
/home/jones/workspace/projects-personal/osv-detector/testdata/locks-many/composer.lock: found 1 package
1339+
Using db Packagist (%% vulnerabilities, including withdrawn - last updated %%)
1340+
1341+
no known vulnerabilities found
1342+
1343+
/home/jones/workspace/projects-personal/osv-detector/testdata/locks-many/yarn.lock: found 1 package
1344+
Using db npm (%% vulnerabilities, including withdrawn - last updated %%)
1345+
1346+
no known vulnerabilities found
1347+
1348+
---
1349+
1350+
[TestRun_Lockfile_AbsolutePath/#01 - 2]
1351+
1352+
---

main_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,53 @@ func TestRun_Lockfile(t *testing.T) {
290290
}
291291
}
292292

293+
func TestRun_Lockfile_AbsolutePath(t *testing.T) {
294+
t.Parallel()
295+
296+
testdataDir, err := filepath.Abs("./testdata")
297+
298+
if err != nil {
299+
t.Fatal(err)
300+
}
301+
302+
tests := []cliTestCase{
303+
{
304+
name: "",
305+
args: []string{filepath.Join(testdataDir, "locks-one")},
306+
exit: 0,
307+
},
308+
{
309+
name: "",
310+
args: []string{filepath.Join(testdataDir, "locks-many")},
311+
exit: 0,
312+
},
313+
{
314+
name: "",
315+
args: []string{filepath.Join(testdataDir, "locks-empty")},
316+
exit: 0,
317+
},
318+
// parse-as + known vulnerability exits with error code 1
319+
{
320+
name: "",
321+
args: []string{"--parse-as", "package-lock.json", filepath.Join(testdataDir, "locks-insecure/my-package-lock.json")},
322+
exit: 1,
323+
},
324+
// json results in non-json output going to stderr
325+
{
326+
name: "",
327+
args: []string{"--json", filepath.Join(testdataDir, "locks-one")},
328+
exit: 0,
329+
},
330+
}
331+
for _, tt := range tests {
332+
t.Run(tt.name, func(t *testing.T) {
333+
t.Parallel()
334+
335+
testCli(t, tt)
336+
})
337+
}
338+
}
339+
293340
func TestRun_DBs(t *testing.T) {
294341
t.Parallel()
295342

0 commit comments

Comments
 (0)