-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
move nuget update analysis to native code #10025
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e294a26
Add analyze command to NuGetUpdater
JoeRobich 10e9cc3
Add first .NET test for analyze
JoeRobich 3d0e92a
Add additional .NET tests
JoeRobich e1e649d
Progress on ruby tests
brettfo 56cd907
More ruby test progress.
brettfo 5a97c14
Handle multi-dependency properties
JoeRobich 5824494
Fix up tests
brettfo e3b8ad0
Fix up tests.
JoeRobich 7a6efcd
Make sorbet and codespell happy
JoeRobich f0b8e02
Fix requirement parsing
JoeRobich b9b8f31
Fix line too long
JoeRobich 1d173db
explicitly specify smoke test branch
brettfo c73e000
return package URL as a part of the dependency info
brettfo cfaffbc
fix spelling
brettfo 7eb87e0
make lint happy
brettfo e80a28d
report _all_ dependencies during discovery, filter results when passi…
brettfo c839998
only use new package analysis with `nuget_native_analysis` experiment
brettfo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Analyze.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
using System.Text; | ||
using System.Xml.Linq; | ||
|
||
using NuGetUpdater.Core; | ||
using NuGetUpdater.Core.Analyze; | ||
using NuGetUpdater.Core.Test; | ||
using NuGetUpdater.Core.Test.Analyze; | ||
using NuGetUpdater.Core.Test.Update; | ||
|
||
using Xunit; | ||
|
||
namespace NuGetUpdater.Cli.Test; | ||
|
||
using TestFile = (string Path, string Content); | ||
|
||
public partial class EntryPointTests | ||
{ | ||
public class Analyze : AnalyzeWorkerTestBase | ||
{ | ||
[Fact] | ||
public async Task FindsUpdatedPackageAndReturnsTheCorrectData() | ||
{ | ||
var repositoryXml = XElement.Parse("""<repository type="git" url="https://nuget.example.com/some.package" />"""); | ||
await RunAsync(path => | ||
[ | ||
"analyze", | ||
"--repo-root", | ||
path, | ||
"--discovery-file-path", | ||
Path.Join(path, "discovery.json"), | ||
"--dependency-file-path", | ||
Path.Join(path, "Some.Package.json"), | ||
"--analysis-folder-path", | ||
Path.Join(path, AnalyzeWorker.AnalysisDirectoryName), | ||
"--verbose", | ||
], | ||
packages: [ | ||
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0", additionalMetadata: [repositoryXml]), | ||
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.1", "net8.0", additionalMetadata: [repositoryXml]), | ||
], | ||
dependencyName: "Some.Package", | ||
initialFiles: | ||
[ | ||
("discovery.json", """ | ||
{ | ||
"Path": "", | ||
"IsSuccess": true, | ||
"Projects": [ | ||
{ | ||
"FilePath": "project.csproj", | ||
"Dependencies": [ | ||
{ | ||
"Name": "Microsoft.NET.Sdk", | ||
"Version": null, | ||
"Type": "MSBuildSdk", | ||
"EvaluationResult": null, | ||
"TargetFrameworks": null, | ||
"IsDevDependency": false, | ||
"IsDirect": false, | ||
"IsTransitive": false, | ||
"IsOverride": false, | ||
"IsUpdate": false | ||
}, | ||
{ | ||
"Name": "Some.Package", | ||
"Version": "1.0.0", | ||
"Type": "PackageReference", | ||
"EvaluationResult": { | ||
"ResultType": "Success", | ||
"OriginalValue": "1.0.0", | ||
"EvaluatedValue": "1.0.0", | ||
"RootPropertyName": null, | ||
"ErrorMessage": null | ||
}, | ||
"TargetFrameworks": [ | ||
"net8.0" | ||
], | ||
"IsDevDependency": false, | ||
"IsDirect": true, | ||
"IsTransitive": false, | ||
"IsOverride": false, | ||
"IsUpdate": false | ||
} | ||
], | ||
"IsSuccess": true, | ||
"Properties": [ | ||
{ | ||
"Name": "TargetFramework", | ||
"Value": "net8.0", | ||
"SourceFilePath": "project.csproj" | ||
} | ||
], | ||
"TargetFrameworks": [ | ||
"net8.0" | ||
], | ||
"ReferencedProjectPaths": [] | ||
} | ||
], | ||
"DirectoryPackagesProps": null, | ||
"GlobalJson": null, | ||
"DotNetToolsJson": null | ||
} | ||
"""), | ||
("Some.Package.json", """ | ||
{ | ||
"Name": "Some.Package", | ||
"Version": "1.0.0", | ||
"IsVulnerable": false, | ||
"IgnoredVersions": [], | ||
"Vulnerabilities": [] | ||
} | ||
"""), | ||
("project.csproj", """ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Some.Package" Version="1.0.0" /> | ||
</ItemGroup> | ||
</Project> | ||
"""), | ||
], | ||
expectedResult: new() | ||
{ | ||
UpdatedVersion = "1.0.1", | ||
CanUpdate = true, | ||
VersionComesFromMultiDependencyProperty = false, | ||
UpdatedDependencies = | ||
[ | ||
new Dependency("Some.Package", "1.0.1", DependencyType.Unknown, TargetFrameworks: ["net8.0"], InfoUrl: "https://nuget.example.com/some.package") | ||
], | ||
} | ||
); | ||
} | ||
|
||
private static async Task RunAsync(Func<string, string[]> getArgs, string dependencyName, TestFile[] initialFiles, ExpectedAnalysisResult expectedResult, MockNuGetPackage[]? packages = null) | ||
{ | ||
var actualResult = await RunAnalyzerAsync(dependencyName, initialFiles, async path => | ||
{ | ||
var sb = new StringBuilder(); | ||
var writer = new StringWriter(sb); | ||
|
||
var originalOut = Console.Out; | ||
var originalErr = Console.Error; | ||
Console.SetOut(writer); | ||
Console.SetError(writer); | ||
|
||
try | ||
{ | ||
await UpdateWorkerTestBase.MockNuGetPackagesInDirectory(packages, path); | ||
var args = getArgs(path); | ||
var result = await Program.Main(args); | ||
if (result != 0) | ||
{ | ||
throw new Exception($"Program exited with code {result}.\nOutput:\n\n{sb}"); | ||
} | ||
} | ||
finally | ||
{ | ||
Console.SetOut(originalOut); | ||
Console.SetError(originalErr); | ||
} | ||
}); | ||
|
||
ValidateAnalysisResult(expectedResult, actualResult); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! Making life simple down the road.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had to re-figure this out too many times.