- Implemented tests for RancherHubConnector to validate fetching documents, handling errors, and managing state. - Added tests for CsafExporter to ensure deterministic serialization of CSAF documents. - Created tests for CycloneDX exporters and reconciler to verify correct handling of VEX claims and output structure. - Developed OpenVEX exporter tests to confirm the generation of canonical OpenVEX documents and statement merging logic. - Introduced Rust file caching and license scanning functionality, including a cache key structure and hash computation. - Added sample Cargo.toml and LICENSE files for testing Rust license scanning functionality.
60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using StellaOps.Scanner.Analyzers.Lang.Rust;
|
|
using StellaOps.Scanner.Analyzers.Lang.Tests.Harness;
|
|
using StellaOps.Scanner.Analyzers.Lang.Tests.TestUtilities;
|
|
|
|
namespace StellaOps.Scanner.Analyzers.Lang.Tests.Rust;
|
|
|
|
public sealed class RustLanguageAnalyzerTests
|
|
{
|
|
[Fact]
|
|
public async Task SimpleFixtureProducesDeterministicOutputAsync()
|
|
{
|
|
var cancellationToken = TestContext.Current.CancellationToken;
|
|
var fixturePath = TestPaths.ResolveFixture("lang", "rust", "simple");
|
|
var goldenPath = Path.Combine(fixturePath, "expected.json");
|
|
|
|
var usageHints = new LanguageUsageHints(new[]
|
|
{
|
|
Path.Combine(fixturePath, "usr/local/bin/my_app")
|
|
});
|
|
|
|
var analyzers = new ILanguageAnalyzer[]
|
|
{
|
|
new RustLanguageAnalyzer()
|
|
};
|
|
|
|
await LanguageAnalyzerTestHarness.AssertDeterministicAsync(
|
|
fixturePath,
|
|
goldenPath,
|
|
analyzers,
|
|
cancellationToken,
|
|
usageHints);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AnalyzerIsThreadSafeUnderConcurrencyAsync()
|
|
{
|
|
var cancellationToken = TestContext.Current.CancellationToken;
|
|
var fixturePath = TestPaths.ResolveFixture("lang", "rust", "simple");
|
|
|
|
var analyzers = new ILanguageAnalyzer[]
|
|
{
|
|
new RustLanguageAnalyzer()
|
|
};
|
|
|
|
var workers = Math.Max(Environment.ProcessorCount, 4);
|
|
var tasks = Enumerable.Range(0, workers)
|
|
.Select(_ => LanguageAnalyzerTestHarness.RunToJsonAsync(fixturePath, analyzers, cancellationToken));
|
|
|
|
var results = await Task.WhenAll(tasks);
|
|
var baseline = results[0];
|
|
foreach (var result in results)
|
|
{
|
|
Assert.Equal(baseline, result);
|
|
}
|
|
}
|
|
}
|