resolve issue with incorrect test fixture content

Signed-off-by: Alan Pope <alan.pope@anchore.com>
This commit is contained in:
Alan Pope 2025-08-26 15:08:43 +01:00
parent 0afe26152f
commit e4f4aa2956
2 changed files with 66 additions and 179 deletions

View File

@ -9,111 +9,56 @@ import (
)
func TestDotnetCsprojCataloger(t *testing.T) {
fixture := "test-fixtures/steeltoe-sample/WeatherForecast.csproj"
fixtureLocationSet := file.NewLocationSet(file.NewLocation(fixture))
fixture := "test-fixtures/weatherforecast-steeltoe"
expectedLocation := file.NewLocation("Sample.csproj")
fixtureLocationSet := file.NewLocationSet(expectedLocation)
expected := []pkg.Package{
{
Name: "Steeltoe.Discovery.Eureka",
Version: "3.2.0",
Name: "Steeltoe.Common.Hosting",
Version: "3.2.*",
FoundBy: "dotnet-csproj-cataloger",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Steeltoe.Discovery.Eureka@3.2.0",
PURL: "pkg:nuget/Steeltoe.Common.Hosting@3.2.%2A",
Locations: fixtureLocationSet,
Metadata: pkg.DotnetDepsEntry{
Name: "Steeltoe.Discovery.Eureka",
Version: "3.2.0",
Path: "test-fixtures/steeltoe-sample",
Name: "Steeltoe.Common.Hosting",
Version: "3.2.*",
Path: ".",
Sha512: "",
HashPath: "",
},
},
{
Name: "Steeltoe.Extensions.Configuration.CloudFoundry",
Version: "3.2.0",
Name: "Steeltoe.Management.EndpointCore",
Version: "3.2.*",
FoundBy: "dotnet-csproj-cataloger",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Steeltoe.Extensions.Configuration.CloudFoundry@3.2.0",
PURL: "pkg:nuget/Steeltoe.Management.EndpointCore@3.2.%2A",
Locations: fixtureLocationSet,
Metadata: pkg.DotnetDepsEntry{
Name: "Steeltoe.Extensions.Configuration.CloudFoundry",
Version: "3.2.0",
Path: "test-fixtures/steeltoe-sample",
Sha512: "",
HashPath: "",
},
},
{
Name: "Steeltoe.Management.Endpoint",
Version: "3.2.0",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Steeltoe.Management.Endpoint@3.2.0",
Locations: fixtureLocationSet,
Metadata: pkg.DotnetDepsEntry{
Name: "Steeltoe.Management.Endpoint",
Version: "3.2.0",
Path: "test-fixtures/steeltoe-sample",
Sha512: "",
HashPath: "",
},
},
{
Name: "Microsoft.AspNetCore.OpenApi",
Version: "8.0.0",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Microsoft.AspNetCore.OpenApi@8.0.0",
Locations: fixtureLocationSet,
Metadata: pkg.DotnetDepsEntry{
Name: "Microsoft.AspNetCore.OpenApi",
Version: "8.0.0",
Path: "test-fixtures/steeltoe-sample",
Name: "Steeltoe.Management.EndpointCore",
Version: "3.2.*",
Path: ".",
Sha512: "",
HashPath: "",
},
},
{
Name: "Swashbuckle.AspNetCore",
Version: "6.5.0",
Version: "6.2.*",
FoundBy: "dotnet-csproj-cataloger",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Swashbuckle.AspNetCore@6.5.0",
PURL: "pkg:nuget/Swashbuckle.AspNetCore@6.2.%2A",
Locations: fixtureLocationSet,
Metadata: pkg.DotnetDepsEntry{
Name: "Swashbuckle.AspNetCore",
Version: "6.5.0",
Path: "test-fixtures/steeltoe-sample",
Sha512: "",
HashPath: "",
},
},
{
Name: "Serilog.AspNetCore",
Version: "8.0.0",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Serilog.AspNetCore@8.0.0",
Locations: fixtureLocationSet,
Metadata: pkg.DotnetDepsEntry{
Name: "Serilog.AspNetCore",
Version: "8.0.0",
Path: "test-fixtures/steeltoe-sample",
Sha512: "",
HashPath: "",
},
},
{
Name: "Serilog.Sinks.Console",
Version: "5.0.0",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Serilog.Sinks.Console@5.0.0",
Locations: fixtureLocationSet,
Metadata: pkg.DotnetDepsEntry{
Name: "Serilog.Sinks.Console",
Version: "5.0.0",
Path: "test-fixtures/steeltoe-sample",
Version: "6.2.*",
Path: ".",
Sha512: "",
HashPath: "",
},
@ -126,86 +71,57 @@ func TestDotnetCsprojCataloger(t *testing.T) {
func TestDotnetCsprojCataloger_GlopsMatch(t *testing.T) {
expectedPackages := []pkg.Package{
{
Name: "Serilog",
Version: "2.10.0",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Serilog@2.10.0",
Name: "Steeltoe.Common.Hosting",
Version: "3.2.*",
FoundBy: "dotnet-csproj-cataloger",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Steeltoe.Common.Hosting@3.2.%2A",
Locations: file.NewLocationSet(file.NewLocation("Sample.csproj")),
Metadata: pkg.DotnetDepsEntry{
Name: "Steeltoe.Common.Hosting",
Version: "3.2.*",
Path: ".",
Sha512: "",
HashPath: "",
},
},
{
Name: "Serilog.Sinks.Console",
Version: "4.0.1",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Serilog.Sinks.Console@4.0.1",
Name: "Steeltoe.Management.EndpointCore",
Version: "3.2.*",
FoundBy: "dotnet-csproj-cataloger",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Steeltoe.Management.EndpointCore@3.2.%2A",
Locations: file.NewLocationSet(file.NewLocation("Sample.csproj")),
Metadata: pkg.DotnetDepsEntry{
Name: "Steeltoe.Management.EndpointCore",
Version: "3.2.*",
Path: ".",
Sha512: "",
HashPath: "",
},
},
{
Name: "Newtonsoft.Json",
Version: "13.0.3",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Newtonsoft.Json@13.0.3",
},
{
Name: "Humanizer",
Version: "2.14.1",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Humanizer@2.14.1",
},
{
Name: "Microsoft.Web.LibraryManager.Build",
Version: "2.1.175",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Microsoft.Web.LibraryManager.Build@2.1.175",
},
{
Name: "Steeltoe.Discovery.Eureka",
Version: "3.2.0",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Steeltoe.Discovery.Eureka@3.2.0",
},
{
Name: "Steeltoe.Extensions.Configuration.CloudFoundry",
Version: "3.2.0",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Steeltoe.Extensions.Configuration.CloudFoundry@3.2.0",
},
{
Name: "Steeltoe.Management.Endpoint",
Version: "3.2.0",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Steeltoe.Management.Endpoint@3.2.0",
},
{
Name: "Microsoft.AspNetCore.OpenApi",
Version: "8.0.0",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Microsoft.AspNetCore.OpenApi@8.0.0",
},
{
Name: "Swashbuckle.AspNetCore",
Version: "6.5.0",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Swashbuckle.AspNetCore@6.5.0",
},
{
Name: "Serilog.AspNetCore",
Version: "8.0.0",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Serilog.AspNetCore@8.0.0",
Name: "Swashbuckle.AspNetCore",
Version: "6.2.*",
FoundBy: "dotnet-csproj-cataloger",
Language: pkg.Dotnet,
Type: pkg.DotnetPkg,
PURL: "pkg:nuget/Swashbuckle.AspNetCore@6.2.%2A",
Locations: file.NewLocationSet(file.NewLocation("Sample.csproj")),
Metadata: pkg.DotnetDepsEntry{
Name: "Swashbuckle.AspNetCore",
Version: "6.2.*",
Path: ".",
Sha512: "",
HashPath: "",
},
},
}
pkgtest.NewCatalogTester().
FromDirectory(t, "test-fixtures").
FromDirectory(t, "test-fixtures/weatherforecast-steeltoe").
Expects(expectedPackages, nil).
TestCataloger(t, NewDotnetCsprojCataloger())
}

View File

@ -1,29 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Steeltoe.Discovery.Eureka" Version="3.2.0" />
<PackageReference Include="Steeltoe.Extensions.Configuration.CloudFoundry" Version="3.2.0" />
<PackageReference Include="Steeltoe.Management.Endpoint" Version="3.2.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
</ItemGroup>
<!-- Development-only packages -->
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" PrivateAssets="All" />
</ItemGroup>
<!-- Build-time analyzers -->
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="All" />
</ItemGroup>
</Project>