-
Notifications
You must be signed in to change notification settings - Fork 737
Added save for PackageSourceMappingsProvider #4709
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
Added save for PackageSourceMappingsProvider #4709
Conversation
|
Are there any UI related changes in this PR? If yes, please consider adding screenshots or a link to spec for reference. |
src/NuGet.Core/NuGet.Configuration/PackageSourceMapping/PackageSourceMappingProvider.cs
Outdated
Show resolved
Hide resolved
| NuGet.Configuration.PackageSourceMappingProvider.SavePackageSourceMappings(System.Collections.Generic.IReadOnlyList<NuGet.Configuration.PackageSourceMappingSourceItem> mappings) -> void | ||
| NuGet.Configuration.PackageSourceMappingProvider.SavePackageSourcesMappings(System.Collections.Generic.IReadOnlyList<NuGet.Configuration.PackageSourceMappingSourceItem> packageSourceMappingsSourceItems, NuGet.Configuration.PackageSourceUpdateOptions sourceUpdateSettings) -> void |
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.
How will customers using the package NuGet.Configuration in their own apps use the two different overloads of SavePackageSourceMappings?
Once APIs become public and we ship to customers, it becomes very difficult in the future to change/remove because we have no way to investigate how many (if any) developers we will break who use these APIs. See also our "changes to APIs" section of the NuGet SDK docs: https://github.com/NuGet/NuGet.Client/blob/dev/docs/nuget-sdk.md#changes-to-apis
I agree that there needs to be public APIs to modify/save PackageSourceMappings. I think it was a significant oversight from an SDK point of view that this was not done when the feature was added in the first place. That has the very unfortunate side-effect that the person who ends up making these public then "bears the responsibility" of considering public API design, rather than the people who implemented the feature/methods in the first place. But once these become public, we have to "support" them for a long time, so I don't want to be reckless and mechanically make existing internal APIs public without considering public API design.
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.
Thanks for pointing this out. Turns out I don't need two save methods. I was copying the method from PackageSourceProvider.cs (which has two save methods) and didn't look closely enough to see if I should just do one instead.
src/NuGet.Core/NuGet.Configuration/PackageSourceMapping/PackageSourceMappingProvider.cs
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| //Remove all old mappings not in new mappings | ||
| if (existingSettingsLookup != null) |
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 believe you may need to reload this value.
Because existingSettingsLookup is stale now, so you may not see new values here.
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.
Yeah I won't see any new values, but I don't think I need to see the mappings that were just added/updated. I really only need to see the ones that are in the config currently but aren't the current list of mappings displayed in the UI. These will still be in existingSettingsLookup even if I add new ones
src/NuGet.Core/NuGet.Configuration/PackageSourceMapping/PackageSourceMappingProvider.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Configuration/PackageSourceMapping/PackageSourceMappingProvider.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Configuration/PackageSourceMapping/PackageSourceMappingProvider.cs
Outdated
Show resolved
Hide resolved
nkolev92
left a comment
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.
You have some pretty good tests and code is pretty easy to follow. 👏
I think we have some duplication in what the newly public methods provider.
src/NuGet.Core/NuGet.Configuration/PackageSourceMapping/PackageSourceMappingProvider.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Configuration/PackageSourceMapping/PackageSourceMappingProvider.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Configuration/PackageSourceMapping/PackageSourceMapping.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.Tests/NuGet.Configuration.Test/PackageSourceMappingProviderTests.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Configuration/PackageSourceMapping/PackageSourceMappingProvider.cs
Outdated
Show resolved
Hide resolved
dominoFire
left a comment
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.
Good job. Just comments. Thank you!
test/NuGet.Core.Tests/NuGet.Configuration.Test/PackageSourceMappingProviderTests.cs
Outdated
Show resolved
Hide resolved
| tempMappings.Add(testMappingItemAdd); | ||
| tempMappings.Remove(testMappingItem2); | ||
|
|
||
| sourceMappingProvider.SavePackageSourceMappings(tempMappings); |
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.
Would this call be the 'act' part of the test?
| sourceMappingProvider.SavePackageSourceMappings(tempMappings); | |
| // Act | |
| sourceMappingProvider.SavePackageSourceMappings(tempMappings); |
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.
Yeah there is a comment on line 602 labeling it "Act & Assert". That is how the other tests in this file seem to be set up, so I just copied how everything else was labeled.
test/NuGet.Core.Tests/NuGet.Configuration.Test/PackageSourceMappingProviderTests.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Configuration/PackageSourceMapping/PackageSourceMappingProvider.cs
Show resolved
Hide resolved
| IReadOnlyList<PackageSourceMappingSourceItem> existingSettingsLookup = GetPackageSourceMappingItems(); | ||
| if (existingSettingsLookup == null) | ||
| { | ||
| return; |
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.
Does this mean packageSourceMapping should exist before this action?
Technically prevent from onboarding. Instead, should it create a new one?
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 removed this if statement because it was a bit redundant. GetPackageSourceMappingItems() will return an empty list of mappings if Package source mappings has not yet been enabled, so existingSettingsLookup will never be null. The Remove() and AddorUpdate() methods have logic that will create a new config if there are no previous mappings
| } | ||
| } | ||
|
|
||
| if (removeMappings != null && removeMappings.Count > 0) |
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.
| if (removeMappings != null && removeMappings.Count > 0) | |
| if (removeMappings.Count > 0) |
You already initialized the list at line 75 so it's not going to be null.
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.
This one is not resolved, so I reverted back to unresolved state.
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.
Oops sorry. I clicked the commit suggestion button, so I thought it was resolved. I guess the commit suggestion button does not actually work? I changed it manually
cbc26b2 to
6b3ae6d
Compare
test/NuGet.Core.Tests/NuGet.Configuration.Test/PackageSourceMappingProviderTests.cs
Show resolved
Hide resolved
erdembayar
left a comment
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.
Great work, almost ready if you address my comment regarding reduce number of new public apis.
| <packageSourceMapping> | ||
| <clear /> | ||
| <packageSource key=""nuget.org""> | ||
| <package pattern=""stuff"" /> |
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.
Do you have test just adding new pattern into existing nuget.org package sourceKey section?
Before:
<packageSource key=""nuget.org"">
<package pattern=""stuff1"" />
</packageSource>
After: Add stufff2
<packageSource key=""nuget.org"">
<package pattern=""stuff1"" />
<package pattern=""stuff2"" />
</packageSource>
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.
Just made a test. SavePackageSourceMappings_NewPatternExistingSource_Add()
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.
Let's wait fingers crossed for CI test results. If CI tests are passing, then I'm ready to approve the PR.
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.
It looks CI tests for your old commit "Remove WhiteSpace" still running, probably cancelling it manually better, because it'll trigger another CI build with latest changes.
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.
@mcnallyella
Few End2end tests are failing due to some reason, please rebase your branch with latest dev branch. Those failing tests are skipped here this morning.
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.
Yes I rebased it. I had a green build a moment ago but had to change a test, so hopefully the next build will be green as well
| <packageSourceMapping> | ||
| <clear /> | ||
| <packageSource key=""nuget.org""> | ||
| <package pattern=""stuff"" /> |
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.
Do you have test just removing 1 pattern from existing nuget.org package sourceKey section?
Before:
<packageSource key=""nuget.org"">
<package pattern=""stuff1"" />
<package pattern=""stuff2"" />
</packageSource>
After: Remove stuff1
<packageSource key=""nuget.org"">
<package pattern=""stuff2"" />
</packageSource>
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.
Just made a test for that. SavePackageSourceMappings_RemovePatternExistingSource_Remove()
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.
Implementation looks great!
I really like how detailed the tests are.
One idea for another test case, and some suggestions for removing duplicate tests.
test/NuGet.Core.Tests/NuGet.Configuration.Test/PackageSourceMappingProviderTests.cs
Show resolved
Hide resolved
test/NuGet.Core.Tests/NuGet.Configuration.Test/PackageSourceMappingProviderTests.cs
Show resolved
Hide resolved
| result.Replace("\r\n", "\n") | ||
| .Should().BeEquivalentTo( | ||
| File.ReadAllText(configPath1).Replace("\r\n", "\n")); | ||
| } |
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 think we need to do one or two more tests.
Multi config tests, where say you have 2 configs, A & B, A is further and has the source mapping clear, but B has a source mapping config for one source, but A has for another one.
I don't expect you to do the same matrix of tests, that'd be an overkill, but at least have a smoke test that ensures the correct one is being updated.
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.
Okay I added a new test called SavePackageSourceMappings_WithTwoConfigs_UseCorrectMapping() to test with two configs.
baa6076 to
5739717
Compare
test/NuGet.Core.Tests/NuGet.Configuration.Test/PackageSourceMappingProviderTests.cs
Show resolved
Hide resolved
test/NuGet.Core.Tests/NuGet.Configuration.Test/PackageSourceMappingProviderTests.cs
Show resolved
Hide resolved
test/NuGet.Core.Tests/NuGet.Configuration.Test/PackageSourceMappingProviderTests.cs
Show resolved
Hide resolved
nkolev92
left a comment
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.
👏
Great job
zivkan
left a comment
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.
Thank you for optimizing the public API surface area.
erdembayar
left a comment
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.
Great work. 👏 👏 👏
Bug
Fixes: NuGet/Home#11935
Regression? Last working version:
Description
I added a method in PackageSourceMappingProvider.cs that saves changes in package source mapping to the config. The save method calls the existing
AddOrUpdatePackageSourceMappingSourceItemandRemovemethods. This will be useful for implementing the options page UI. I also added 4 tests for the save method. There is also a draft PR with the changes to the options UI for package source mapping: #4711PR Checklist
PR has a meaningful title
PR has a linked issue.
Described changes
Tests
Documentation