public async Task FeedConfigParserTests1Async() { var buildEngine = new MockBuildEngine(); var task = new PublishArtifactsInManifestV2 { // Create a single Microsoft.Build.Utilities.TaskItem for a simple feed config, then parse to FeedConfigs and // check the expected values. TargetFeedConfig = new Microsoft.Build.Utilities.TaskItem[] { new Microsoft.Build.Utilities.TaskItem(TargetFeedContentType.BinaryLayout.ToString(), new Dictionary <string, string> { { "TargetUrl", BlobFeedUrl }, { "Token", RandomToken }, { "Type", "AzDoNugetFeed" }, { "Internal", "false" } }), }, BuildEngine = buildEngine }; await task.ParseTargetFeedConfigAsync(); task.Log.HasLoggedErrors.Should().BeFalse(); // This will have set the feed configs. task.FeedConfigs.Should().ContainKey(TargetFeedContentType.BinaryLayout).WhichValue.Should().SatisfyRespectively( config => { config.Token.Should().Be(RandomToken); config.TargetURL.Should().Be(BlobFeedUrl); config.Internal.Should().BeFalse(); config.Type.Should().Be(FeedType.AzDoNugetFeed); config.AssetSelection.Should().Be(AssetSelection.All); }); }
public async Task FeedConfigParserTests5Async() { var buildEngine = new MockBuildEngine(); var task = new PublishArtifactsInManifestV2 { InternalBuild = true, TargetFeedConfig = new Microsoft.Build.Utilities.TaskItem[] { new Microsoft.Build.Utilities.TaskItem("FOOPACKAGES", new Dictionary <string, string> { { "TargetUrl", BlobFeedUrl }, { "Token", RandomToken }, { "Type", "AZURESTORAGEFEED" }, { "AssetSelection", "SHIPPINGONLY" }, { "Internal", "true" } }), new Microsoft.Build.Utilities.TaskItem("FOOPACKAGES", new Dictionary <string, string> { { "TargetUrl", BlobFeedUrl }, { "Token", RandomToken }, { "Type", "AZURESTORAGEFEED" }, { "AssetSelection", "SHIPPINGONLY" } }), }, BuildEngine = buildEngine }; await task.ParseTargetFeedConfigAsync(); // Verify that the checker errors on attempts to publish internal // artifacts to non-internal feeds task.Log.HasLoggedErrors.Should().BeTrue(); buildEngine.BuildErrorEvents.Should().Contain(e => e.Message.Equals($"Use of non-internal feed '{BlobFeedUrl}' is invalid for an internal build. This can be overridden with '{nameof(PublishArtifactsInManifest.SkipSafetyChecks)}= true'")); }
public async Task FeedConfigParserTests6Async() { var buildEngine = new MockBuildEngine(); var task = new PublishArtifactsInManifestV2 { InternalBuild = true, TargetFeedConfig = new Microsoft.Build.Utilities.TaskItem[] { new Microsoft.Build.Utilities.TaskItem(TargetFeedContentType.Checksum.ToString(), new Dictionary <string, string> { { "TargetUrl", BlobFeedUrl }, { "Token", RandomToken }, { "Type", "AZURESTORAGEFEED" }, { "AssetSelection", "SHIPPINGONLY" }, { "Internal", "true" } }), new Microsoft.Build.Utilities.TaskItem(TargetFeedContentType.Maven.ToString(), new Dictionary <string, string> { { "TargetUrl", BlobFeedUrl }, { "Token", RandomToken }, { "Type", "AZURESTORAGEFEED" }, { "AssetSelection", "SHIPPINGONLY" }, { "Internal", "true" } }), }, BuildEngine = buildEngine }; await task.ParseTargetFeedConfigAsync(); task.Log.HasLoggedErrors.Should().BeFalse(); }
public async Task FeedConfigParserTests4Async() { var buildEngine = new MockBuildEngine(); var task = new PublishArtifactsInManifestV2 { TargetFeedConfig = new Microsoft.Build.Utilities.TaskItem[] { new Microsoft.Build.Utilities.TaskItem(TargetFeedContentType.BinaryLayout.ToString(), new Dictionary <string, string> { { "TargetUrl", BlobFeedUrl }, { "Token", RandomToken }, // Use different casing here to make sure that parsing // ignores case. { "Type", "AZURESTORAGEFEED" }, { "AssetSelection", "SHIPPINGONLY" }, { "Internal", "false" } }), }, BuildEngine = buildEngine }; await task.ParseTargetFeedConfigAsync(); // This will have set the feed configs. task.FeedConfigs.Should().ContainKey(TargetFeedContentType.BinaryLayout).WhichValue.Should().SatisfyRespectively( config => { config.Token.Should().Be(RandomToken); config.TargetURL.Should().Be(BlobFeedUrl); config.Type.Should().Be(FeedType.AzureStorageFeed); config.AssetSelection.Should().Be(AssetSelection.ShippingOnly); }); }
public async Task StableAssetCheckV2Async(string assetVersion, bool isIsolatedFeed, bool shouldError, bool isReleaseOnlyPackageVersion = false, bool skipChecks = false) { const string packageId = "Foo.Package"; BuildIdentity buildIdentity = new BuildIdentity { IsReleaseOnlyPackageVersion = isReleaseOnlyPackageVersion }; BuildModel buildModel = new BuildModel(buildIdentity) { Artifacts = new ArtifactSet { Blobs = new List <BlobArtifactModel>(), Packages = new List <PackageArtifactModel> { new PackageArtifactModel() { Id = packageId, Version = assetVersion } } } }; var buildEngine = new MockBuildEngine(); var task = new PublishArtifactsInManifestV2 { SkipSafetyChecks = skipChecks, TargetFeedConfig = new MsBuildUtils.TaskItem[] { new MsBuildUtils.TaskItem("PACKAGE", new Dictionary <string, string> { { "TargetUrl", BlobFeedUrl }, { "Token", RandomToken }, { "Type", "AZURESTORAGEFEED" }, { "AssetSelection", "SHIPPINGONLY" }, { "Internal", "false" }, { "Isolated", isIsolatedFeed.ToString() } }) }, BuildEngine = buildEngine, BuildModel = buildModel }; await task.ParseTargetFeedConfigAsync(); task.Log.HasLoggedErrors.Should().BeFalse(); task.SplitArtifactsInCategories(buildModel); task.Log.HasLoggedErrors.Should().BeFalse(); task.CheckForStableAssetsInNonIsolatedFeeds(); task.Log.HasLoggedErrors.Should().Be(shouldError); if (shouldError) { buildEngine.BuildErrorEvents.Should().Contain(e => e.Message.Equals($"Package '{packageId}' has stable version '{assetVersion}' but is targeted at a non-isolated feed '{BlobFeedUrl}'")); } }
public async Task FeedConfigParserTests3Async() { var buildEngine = new MockBuildEngine(); var task = new PublishArtifactsInManifestV2 { TargetFeedConfig = new Microsoft.Build.Utilities.TaskItem[] { new Microsoft.Build.Utilities.TaskItem("FOOPACKAGES", new Dictionary <string, string> { { "TargetUrl", string.Empty }, { "Token", string.Empty }, { "Type", string.Empty }, { "Internal", "false" } }), }, BuildEngine = buildEngine }; await task.ParseTargetFeedConfigAsync(); task.Log.HasLoggedErrors.Should().BeTrue(); buildEngine.BuildErrorEvents.Should().Contain(e => e.Message.Equals("Invalid FeedConfig entry. TargetURL='' Type='' Token=''")); }
public async Task FeedConfigParserTests2Async() { var buildEngine = new MockBuildEngine(); var task = new PublishArtifactsInManifestV2 { TargetFeedConfig = new Microsoft.Build.Utilities.TaskItem[] { new Microsoft.Build.Utilities.TaskItem("FOOPACKAGES", new Dictionary <string, string> { { "TargetUrl", BlobFeedUrl }, { "Token", RandomToken }, { "Type", "MyUnknownFeedType" }, { "Internal", "false" } }), }, BuildEngine = buildEngine }; await task.ParseTargetFeedConfigAsync(); Assert.True(task.Log.HasLoggedErrors); Assert.Contains(buildEngine.BuildErrorEvents, e => e.Message.Equals("Invalid feed config type 'MyUnknownFeedType'. Possible values are: AzDoNugetFeed, AzureStorageFeed")); }
public async Task FeedConfigParserTests1Async() { var buildEngine = new MockBuildEngine(); var task = new PublishArtifactsInManifestV2 { // Create a single Microsoft.Build.Utilities.TaskItem for a simple feed config, then parse to FeedConfigs and // check the expected values. TargetFeedConfig = new Microsoft.Build.Utilities.TaskItem[] { new Microsoft.Build.Utilities.TaskItem(TargetFeedContentType.BinaryLayout.ToString(), new Dictionary <string, string> { { "TargetUrl", BlobFeedUrl }, { "Token", RandomToken }, { "Type", "AzDoNugetFeed" }, { "Internal", "false" } }), }, BuildEngine = buildEngine }; await task.ParseTargetFeedConfigAsync(); Assert.False(task.Log.HasLoggedErrors); // This will have set the feed configs. Assert.Collection(task.FeedConfigs, configList => { Assert.Equal(TargetFeedContentType.BinaryLayout, configList.Key); Assert.Collection(configList.Value, config => { Assert.Equal(RandomToken, config.Token); Assert.Equal(BlobFeedUrl, config.TargetURL); Assert.False(config.Internal); Assert.Equal(FeedType.AzDoNugetFeed, config.Type); Assert.Equal(AssetSelection.All, config.AssetSelection); }); }); }
public async Task FeedConfigParserTests4Async() { var buildEngine = new MockBuildEngine(); var task = new PublishArtifactsInManifestV2 { TargetFeedConfig = new Microsoft.Build.Utilities.TaskItem[] { new Microsoft.Build.Utilities.TaskItem(TargetFeedContentType.BinaryLayout.ToString(), new Dictionary <string, string> { { "TargetUrl", BlobFeedUrl }, { "Token", RandomToken }, // Use different casing here to make sure that parsing // ignores case. { "Type", "AZURESTORAGEFEED" }, { "AssetSelection", "SHIPPINGONLY" }, { "Internal", "false" } }), }, BuildEngine = buildEngine }; await task.ParseTargetFeedConfigAsync(); // This will have set the feed configs. Assert.Collection(task.FeedConfigs, configList => { Assert.Equal(TargetFeedContentType.BinaryLayout, configList.Key); Assert.Collection(configList.Value, config => { Assert.Equal(RandomToken, config.Token); Assert.Equal(BlobFeedUrl, config.TargetURL); Assert.Equal(FeedType.AzureStorageFeed, config.Type); Assert.Equal(AssetSelection.ShippingOnly, config.AssetSelection); }); }); }
public async Task PushNugetPackageTestsAsync(int pushAttemptsBeforeSuccess, bool packageAlreadyOnFeed, bool localPackageMatchesFeed, bool expectedFailure = false) { // Setup var buildEngine = new MockBuildEngine(); // May as well check that the exe is plumbed through from the task. string fakeNugetExeName = $"{Path.GetRandomFileName()}.exe"; int timesNugetExeCalled = 0; // Functionality is the same as this is in the base class, create a v2 object to test. var task = new PublishArtifactsInManifestV2 { InternalBuild = true, BuildEngine = buildEngine, NugetPath = fakeNugetExeName, MaxRetryCount = 5, // In case the default changes, lock to 5 so the test data works RetryDelayMilliseconds = 10 // retry faster in test }; TargetFeedConfig config = new TargetFeedConfig(TargetFeedContentType.Package, "testUrl", FeedType.AzDoNugetFeed, "tokenValue"); Func <string, string, HttpClient, MsBuildUtils.TaskLoggingHelper, Task <PackageFeedStatus> > testCompareLocalPackage = async(string localPackageFullPath, string packageContentUrl, HttpClient client, MsBuildUtils.TaskLoggingHelper log) => { await(Task.Delay(10)); // To make this actually async Debug.WriteLine($"Called mocked CompareLocalPackageToFeedPackage() : localPackageFullPath = {localPackageFullPath}, packageContentUrl = {packageContentUrl}"); if (packageAlreadyOnFeed) { return(localPackageMatchesFeed ? PackageFeedStatus.ExistsAndIdenticalToLocal : PackageFeedStatus.ExistsAndDifferent); } else { return(PackageFeedStatus.DoesNotExist); } }; Func <string, string, Task <ProcessExecutionResult> > testRunAndLogProcess = (string fakeExePath, string fakeExeArgs) => { Debug.WriteLine($"Called mocked RunProcessAndGetOutputs() : ExePath = {fakeExePath}, ExeArgs = {fakeExeArgs}"); fakeNugetExeName.Should().Be(fakeExePath); ProcessExecutionResult result = new ProcessExecutionResult() { StandardError = "fake stderr", StandardOut = "fake stdout" }; timesNugetExeCalled++; if (timesNugetExeCalled >= pushAttemptsBeforeSuccess) { result.ExitCode = 0; } else { result.ExitCode = 1; } return(Task.FromResult(result)); }; await task.PushNugetPackageAsync( config, null, "localPackageLocation", "1234", "version", "feedaccount", "feedvisibility", "feedname", testCompareLocalPackage, testRunAndLogProcess); if (!expectedFailure && localPackageMatchesFeed) { // Successful retry scenario; make sure we ran the # of retries we thought. timesNugetExeCalled.Should().BeLessOrEqualTo(task.MaxRetryCount); } expectedFailure.Should().Be(task.Log.HasLoggedErrors); }