-
Notifications
You must be signed in to change notification settings - Fork 19
Update feed2catalog and catalog2registration to properly handle SemVer 2.0.0 #145
Conversation
🔔 |
Will rebase to fix merge conflict. 🔔 |
Rebased. Ready for some 👀 |
} | ||
|
||
public static bool IsGraphSemVer2(string version, string resourceUri, IGraph graph) | ||
{ |
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.
May need some argument checks on this utility class.
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.
Fixed.
: base(index, new Uri[] { Schema.DataTypes.PackageDetails, Schema.DataTypes.PackageDelete }, handlerFunc) | ||
{ | ||
_storageFactory = storageFactory; | ||
_semVer1StorageFactory = semVer1StorageFactory; |
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.
nit: technically, it is not a SemVer v1.0 storage factory, as it may also contain System.Versioning
-style packages. Perhaps rename to legacyStorageFactory
, or fallbackStorageFactory
, or something along those lines?
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.
Legacy seems right. However I think our the definition in NuGet world is always going to be blurred. For example 1.0.0.1-alpha.1
is considered "SemVer 2.0.0" by NuGet.
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.
Fixed.
@@ -40,22 +42,17 @@ public string LowerCase(string original) | |||
|
|||
public string NormalizeVersion(string original) |
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 we need those thin wrappers? Can use NuGetVersionUtility directly
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 chose to wrap thinly here because XsltHelper
needs to be called via an instance method. NuGetVersionUtility
is static so it's easily consumable by different jobs.
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using VDS.RDF; | ||
|
||
namespace NuGet.Services.Metadata.Catalog.Registration | ||
{ | ||
public delegate bool ShouldIncludeRegistrationPackage(RegistrationEntryKey key, string resourceUri, IGraph graph); |
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.
move the delegate inside ShouldIncludeRegistrationPackage. Will make the code more readable.
Also, it's not clear how it's used. You can improve the name or add 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.
Not sure what you mean by:
move the delegate inside ShouldIncludeRegistrationPackage
The delegate itself is called ShouldIncludeRegistrationPackage
. I chose not to put it inside RegistrationCatalogEntry
because this delegate is passed from a couple levels up, which do not have knowledge of RegistrationCatalogEntry
.
In general, delegates are just types so I see no reason why they should be nested.
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 meant to move it inside RegistrationCatalogEntry, but I agree with your logic. However, the name is still confusing and needs a comment/better name.
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.
Latest revision has XML docs now.
{ | ||
return RegistrationMaker.Process( | ||
await RegistrationMaker.Process( |
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.
please add named parameters to improve readability
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.
Fixed.
: base(index, new Uri[] { Schema.DataTypes.PackageDetails, Schema.DataTypes.PackageDelete }, handlerFunc) | ||
{ | ||
_storageFactory = storageFactory; | ||
_semVer1StorageFactory = semVer1StorageFactory; |
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.
null checks
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.
Fixed.
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.
nitpicks
@@ -60,10 +68,11 @@ protected override void Init(IDictionary<string, string> arguments, Cancellation | |||
|
|||
var contentBaseAddress = arguments.GetOrDefault<string>(Arguments.ContentBaseAddress); | |||
|
|||
StorageFactory storageFactoryToUse; | |||
StorageFactory legacyStorageFactory; |
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 it may be worthwhile to have a comment here (and potentially in RegistrationCollector
as well) about what precisely is "legacy" about the legacyStorageFactory
.
As far as I understand, the legacyStorageFactory
writes non-gzipped non-semver2 registration blobs and gzipped non-semver2 registration blobs. These are considered legacy because vCurrent nuget.exe
always reads the gzipped semver2 registration blobs.
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.
sure
{ | ||
// Arrange | ||
var graph = InitializeGraph(ResourceUri, Id, Version); | ||
var isDelegateInvoked = false; |
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.
nitpick: use a helper function/class to share the delegate code between tests
private class IsDelegateInvokedHelper
{
public IsDelegateInvokedHelper()
{
IsDelegateInvoked = false;
ShouldInclude = (k, u, g) => { ... }
}
public ShouldIncludeRegistrationPackage ShouldInclude { get; private set; }
public bool IsDelegateInvoked {get; private set; }
}
tests/NgTests/Feed2CatalogTests.cs
Outdated
Listed = false, | ||
|
||
Created = new DateTime(2015, 1, 1), | ||
LastEdited = new DateTime(2015, 1, 1), |
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.
nitpick:
I understand the other ODataPackage
s do this as well, but I don't think it's possible to have a Created
and LastEdited
be the exact same. We should probably test realistic values rather than those that cannot happen.
public async Task CreatesRegistrationsWithSemVer2() | ||
{ | ||
// Arrange | ||
var catalogStorage = Catalogs.CreateTestCatalogWithSemVer2Package(); |
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.
nitpick:
a lot of the code here is nearly identical to that in SharedInit
, just with the added SemVer2 storage. I would suggest modifying SharedInit
to support SemVer2 storage as well (private void SharedInit(bool useSemVer2)
.
public async Task IgnoresSemVer2Packages() | ||
{ | ||
// Arrange | ||
var catalogStorage = Catalogs.CreateTestCatalogWithSemVer2Package(); |
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.
Use SharedInit
?
{ Arguments.StorageType, storageType}, | ||
{ Arguments.UseCompressedStorage, "false"} | ||
{ Arguments.StorageType, storageType }, | ||
{ Arguments.UseCompressedStorage, "false" } |
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.
typos in method names in this class
AzureCommpressedFactoryNull
-> AzureCompressedFactoryNull
AzureCommpressedFactory
-> AzureCompressedFactory
@@ -61,12 +61,12 @@ internal class TestLogger : ILogger | |||
{ | |||
public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter) | |||
{ | |||
Console.WriteLine($"{logLevel}: {formatter(state, exception)}"); | |||
// Console.WriteLine($"{logLevel}: {formatter(state, exception)}"); |
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.
Why not?
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 was causing tests to have a lot of stdout (locally and on CI). 99% of the time, you only fail about the failure result, not the stdout.
Merged into "semver2" feature branch until I do some more validation. |
…r 2.0.0 (#145) * Update feed2catalog and catalog2registration to properly handle SemVer 2.0.0 * Add testing for NuGetVersionUtility * Add integration tests for creation of catalog items (feed2catalog) * Add tests for PackageCatalogItem * Add unit tests for RegistrationCatalogEntry and PackagesFolderPackagePathProvider * Only call the SemVer 2.0.0 storage factory if it was provided * Add tests for the SemVer 2.0.0 storage factory * Update Feed2Catalog tests to add a SemVer2 package * Add functional tests for registration collector * Addresses NuGet/NuGetGallery#3560 * Addresses NuGet/NuGetGallery#3680
…r 2.0.0 (#145) * Update feed2catalog and catalog2registration to properly handle SemVer 2.0.0 * Add testing for NuGetVersionUtility * Add integration tests for creation of catalog items (feed2catalog) * Add tests for PackageCatalogItem * Add unit tests for RegistrationCatalogEntry and PackagesFolderPackagePathProvider * Only call the SemVer 2.0.0 storage factory if it was provided * Add tests for the SemVer 2.0.0 storage factory * Update Feed2Catalog tests to add a SemVer2 package * Add functional tests for registration collector * Addresses NuGet/NuGetGallery#3560 * Addresses NuGet/NuGetGallery#3680
Addresses NuGet/NuGetGallery#3560 and NuGet/NuGetGallery#3680.