Skip to content

Commit

Permalink
fix(rust): cover more edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bodinsamuel committed Aug 7, 2023
1 parent 97151e6 commit 2c2276e
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 5 deletions.
65 changes: 61 additions & 4 deletions src/analyser/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ exports[`analyser > should run correctly 1`] = `
],
],
"edges": [],
"id": "18",
"id": "19",
"inComponent": null,
"languages": {},
"name": "GCP",
Expand All @@ -275,7 +275,7 @@ exports[`analyser > should run correctly 1`] = `
],
],
"edges": [],
"id": "19",
"id": "20",
"inComponent": null,
"languages": {},
"name": "Vercel",
Expand All @@ -285,6 +285,30 @@ exports[`analyser > should run correctly 1`] = `
"tech": "vercel",
"techs": [],
},
{
"childs": [],
"dependencies": [
[
"rustcargo",
"dotenv",
"0.15.0",
],
],
"edges": [],
"id": "17",
"inComponent": null,
"languages": {
"TOML": 1,
},
"name": "rust-server",
"path": [
"/pkgs/rust/Cargo.toml",
],
"tech": null,
"techs": [
"rust",
],
},
],
"dependencies": [
[
Expand Down Expand Up @@ -515,7 +539,7 @@ exports[`analyser > should run correctly 2`] = `
],
],
"edges": [],
"id": "18",
"id": "19",
"inComponent": null,
"languages": {},
"name": "GCP",
Expand Down Expand Up @@ -606,6 +630,7 @@ exports[`analyser > should run correctly 2`] = `
"HTML": 1,
"JSON": 3,
"SCSS": 1,
"TOML": 1,
"YAML": 1,
},
"name": "fake",
Expand Down Expand Up @@ -642,6 +667,30 @@ exports[`analyser > should run correctly 2`] = `
"tech": "redis",
"techs": [],
},
{
"childs": [],
"dependencies": [
[
"rustcargo",
"dotenv",
"0.15.0",
],
],
"edges": [],
"id": "17",
"inComponent": null,
"languages": {
"TOML": 1,
},
"name": "rust-server",
"path": [
"/pkgs/rust/Cargo.toml",
],
"tech": null,
"techs": [
"rust",
],
},
{
"childs": [],
"dependencies": [
Expand Down Expand Up @@ -742,6 +791,11 @@ exports[`analyser > should run correctly 2`] = `
"vite",
"4.3.3",
],
[
"rustcargo",
"dotenv",
"0.15.0",
],
[
"terraform",
"registry.terraform.io/hashicorp/google",
Expand Down Expand Up @@ -774,13 +828,14 @@ exports[`analyser > should run correctly 2`] = `
],
],
"edges": [],
"id": "20",
"id": "21",
"inComponent": null,
"languages": {
"HCL": 2,
"HTML": 3,
"JSON": 8,
"SCSS": 3,
"TOML": 3,
"YAML": 2,
},
"name": "flatten",
Expand All @@ -790,6 +845,7 @@ exports[`analyser > should run correctly 2`] = `
"/pkgs/api/package.json",
"/pkgs/app/package.json",
"/terraform/.terraform.lock.hcl",
"/pkgs/rust/Cargo.toml",
"/package.json",
],
"tech": null,
Expand All @@ -806,6 +862,7 @@ exports[`analyser > should run correctly 2`] = `
"prisma",
"react",
"redis",
"rust",
"scss",
"terraform",
"typescript",
Expand Down
35 changes: 35 additions & 0 deletions src/rules/spec/rust/__snapshots__/component.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,38 @@ exports[`rust (component) > should match everything 2`] = `
],
]
`;

exports[`rust (component) > should match foreign dependencies 1`] = `
[
[
"rustcargo",
"anyhow",
"1.0.56",
],
[
"rustcargo",
"axum",
"0.6.1",
],
[
"rustcargo",
"foobar",
"^1.0.0",
],
[
"rustcargo",
"hello",
"path:../world:1.0.0",
],
[
"rustcargo",
"redis_cluster_async",
"git:https://github.com/redis-rs/redis-cluster-async.git#e6fe168",
],
[
"rustcargo",
"test",
"path:../test",
],
]
`;
35 changes: 35 additions & 0 deletions src/rules/spec/rust/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,39 @@ version = "1.8.0"
expect(merged.techs).toMatchSnapshot();
expect(Array.from(merged.dependencies).sort()).toMatchSnapshot();
});

it('should match foreign dependencies', async () => {
const lockfile: string[] = [
`[package]
name = "svix-server"
version = "1.8.0"
[dependencies]
test = { path = "../test" }
hello = { path = "../world", version = "1.0.0" }
axum = { version = "0.6.1", features = ["headers"] }
[dev-dependencies]
anyhow = "1.0.56"
redis_cluster_async = { git = "https://github.com/redis-rs/redis-cluster-async.git", rev = "e6fe168" }
[build-dependencies]
foobar = "^1.0.0"
`,
];

const res = await analyser({
provider: new FakeProvider({
paths: {
'/': ['Cargo.toml'],
},
files: {
'/Cargo.toml': lockfile.join(''),
},
}),
});

const merged = flatten(res, { merge: true });
expect(Array.from(merged.dependencies).sort()).toMatchSnapshot();
});
});
2 changes: 1 addition & 1 deletion src/rules/spec/rust/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const detectRustComponent: ComponentMatcher = async (
return [
'rustcargo',
name,
`path:${value.path}${value.version || ''}`,
`path:${value.path}${value.version ? `:${value.version}` : ''}`,
];
}
if ('git' in value) {
Expand Down
8 changes: 8 additions & 0 deletions tests/__fixtures__/pkgs/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "rust-server"
version = "1.0.0"
license = "MIT"
description = "Foobar"

[dependencies]
dotenv = "0.15.0"

0 comments on commit 2c2276e

Please sign in to comment.