Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions test/fixtures/cargo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions test/fixtures/cargo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "fixture-cargo"
version = "0.1.0"

[dependencies]
serde = "1.0.0"

[dev-dependencies]
tokio = { version = "1.37.0", features = ["full"] }
8 changes: 8 additions & 0 deletions test/fixtures/composer/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"require": {
"laravel/framework": "^11.0"
},
"require-dev": {
"phpunit/phpunit": "^11.0"
}
}
28 changes: 28 additions & 0 deletions test/fixtures/composer/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test/fixtures/dart/pubspec.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
packages:
http:
dependency: "direct main"
description:
name: http
source: hosted
version: "1.2.1"
test:
dependency: "direct dev"
description:
name: test
source: hosted
version: "1.25.2"
sdks:
dart: ">=3.0.0 <4.0.0"
7 changes: 7 additions & 0 deletions test/fixtures/dart/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: fixture_dart

dependencies:
http: ^1.2.1

dev_dependencies:
test: ^1.25.2
5 changes: 5 additions & 0 deletions test/fixtures/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ARG BASE_IMAGE=python:3.11-slim
FROM --platform=linux/amd64 $BASE_IMAGE AS base
FROM base AS test
FROM scratch AS export
FROM alpine:3.19
7 changes: 7 additions & 0 deletions test/fixtures/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
api:
image: redis:7.2
worker:
build: .
db:
image: postgres:16
8 changes: 8 additions & 0 deletions test/fixtures/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module example.com/fixture

go 1.21

require (
github.com/gin-gonic/gin v1.9.1
github.com/stretchr/testify v1.8.4 // indirect
)
8 changes: 8 additions & 0 deletions test/fixtures/gradle/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id "java"
}

dependencies {
implementation "org.springframework:spring-core:6.1.0"
testImplementation "junit:junit:4.13.2"
}
2 changes: 2 additions & 0 deletions test/fixtures/gradle/gradle.lockfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework:spring-core:6.1.0=compileClasspath
junit:junit:4.13.2=testCompileClasspath
5 changes: 5 additions & 0 deletions test/fixtures/helm/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dependencies:
- name: redis
version: 19.6.0
digest: sha256:fixture
generated: "2026-04-05T00:00:00Z"
6 changes: 6 additions & 0 deletions test/fixtures/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: fixture-chart
version: 0.1.0
dependencies:
- name: redis
version: 19.6.0
16 changes: 16 additions & 0 deletions test/fixtures/hex/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
defmodule FixtureHex.MixProject do
use Mix.Project

def project do
[
app: :fixture_hex,
version: "0.1.0"
]
end

defp deps do
[
{:jason, "~> 1.4"}
]
end
end
3 changes: 3 additions & 0 deletions test/fixtures/hex/mix.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%{
"jason": {:hex, :jason, "1.4.1", "checksum", [:mix], [], "hexpm", "checksum"}
}
5 changes: 5 additions & 0 deletions test/fixtures/nuget/Fixture.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>
18 changes: 18 additions & 0 deletions test/fixtures/nuget/packages.lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": 1,
"dependencies": {
".NETCoreApp,Version=v8.0": {
"Newtonsoft.Json": {
"type": "Direct",
"resolved": "13.0.3",
"dependencies": {
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
}
},
"System.Runtime.CompilerServices.Unsafe": {
"type": "Transitive",
"resolved": "6.0.0"
}
}
}
}
3 changes: 3 additions & 0 deletions test/fixtures/ruby/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gem "rails", "~> 7.1.3"
9 changes: 9 additions & 0 deletions test/fixtures/ruby/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
GEM
remote: https://rubygems.org/
specs:
rails (7.1.3)
actionpack (= 7.1.3)
actionpack (7.1.3)

DEPENDENCIES
rails (~> 7.1.3)
14 changes: 14 additions & 0 deletions test/fixtures/swift/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions test/fixtures/swift/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// swift-tools-version: 5.9
import PackageDescription

let package = Package(
name: "FixtureSwift",
dependencies: [
.package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.8.0")
]
)
119 changes: 119 additions & 0 deletions test/lockfileParsers/cargoParser.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
const assert = require("assert");
const path = require("path");
const cargoParser = require("../../util/lockfileParsers/cargoParser");
const {
makeTempWorkspace,
removeDirectory,
writeTextFile,
} = require("../helpers/fixtureWorkspace");

suite("cargoParser Test Suite", () => {
const fixtureDir = path.join(__dirname, "..", "fixtures", "cargo");
const tempDirs = [];

async function createWorkspace() {
const workspace = await makeTempWorkspace("cloudsmith-cargo-parser-");
tempDirs.push(workspace);
return workspace;
}

suiteTeardown(async () => {
await Promise.all(tempDirs.map((tempDir) => removeDirectory(tempDir)));
});

test("resolves Cargo.lock uniquely, skips the root package, and marks direct dependencies from Cargo.toml", async () => {
const tree = await cargoParser.resolve({
lockfilePath: path.join(fixtureDir, "Cargo.lock"),
manifestPath: path.join(fixtureDir, "Cargo.toml"),
});

assert.strictEqual(tree.sourceFile, "Cargo.lock");
assert.strictEqual(tree.dependencies.length, 3);
assert.strictEqual(tree.dependencies.some((dependency) => dependency.name === "fixture-cargo"), false);

const serde = tree.dependencies.find((dependency) => dependency.name === "serde");
const tokio = tree.dependencies.find((dependency) => dependency.name === "tokio");
const bytes = tree.dependencies.find((dependency) => dependency.name === "bytes");

assert.ok(serde);
assert.ok(tokio);
assert.ok(bytes);
assert.strictEqual(serde.isDirect, true);
assert.strictEqual(tokio.isDirect, true);
assert.strictEqual(bytes.isDirect, false);
assert.deepStrictEqual(bytes.parentChain, ["tokio"]);
});

test("detect returns no matches when Cargo files are missing", async () => {
const workspace = await createWorkspace();

const matches = await cargoParser.detect(workspace);

assert.deepStrictEqual(matches, []);
assert.strictEqual(await cargoParser.canResolve(workspace), false);
});

test("throws for malformed Cargo.lock files", async () => {
const workspace = await createWorkspace();
const lockfilePath = path.join(workspace, "Cargo.lock");
const manifestPath = path.join(workspace, "Cargo.toml");
await writeTextFile(lockfilePath, "[[package]]\nname = \"broken\"\n");
await writeTextFile(manifestPath, "[dependencies]\nserde = \"1.0.0\"\n");

await assert.rejects(
() => cargoParser.resolve({ lockfilePath, manifestPath }),
/Malformed Cargo\.lock: no package entries found/
);
});

test("deduplicates large Cargo graphs down to unique packages", async () => {
const workspace = await createWorkspace();
const lockfilePath = path.join(workspace, "Cargo.lock");
const manifestPath = path.join(workspace, "Cargo.toml");
const packageCount = 300;
const registrySource = "registry+https://github.com/rust-lang/crates.io-index";

const manifestLines = [
"[package]",
'name = "fixture-cargo"',
'version = "0.1.0"',
"",
"[dependencies]",
'crate-000 = "1.0.0"',
];

const lockEntries = [];
for (let index = 0; index < packageCount; index += 1) {
const currentName = `crate-${String(index).padStart(3, "0")}`;
const nextName = index + 1 < packageCount
? `crate-${String(index + 1).padStart(3, "0")}`
: null;
lockEntries.push(
[
"[[package]]",
`name = "${currentName}"`,
'version = "1.0.0"',
`source = "${registrySource}"`,
nextName
? `dependencies = ["${nextName} 1.0.0"]`
: "",
"",
].filter(Boolean).join("\n")
);
}

await writeTextFile(manifestPath, manifestLines.join("\n"));
await writeTextFile(lockfilePath, lockEntries.join("\n"));

const tree = await cargoParser.resolve({
lockfilePath,
manifestPath,
});

assert.strictEqual(tree.dependencies.length, packageCount);
assert.strictEqual(
new Set(tree.dependencies.map((dependency) => `${dependency.name}@${dependency.version}`)).size,
packageCount
);
});
});
Loading