Exemple #1
0
        public async Task FeedConfigParserTests5Async()
        {
            var buildEngine = new MockBuildEngine();
            var task        = new PublishArtifactsInManifest
            {
                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
            Assert.True(task.Log.HasLoggedErrors);
            Assert.Contains(buildEngine.BuildErrorEvents, 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'"));
        }
Exemple #2
0
        public async Task FeedConfigParserTests6Async()
        {
            var buildEngine = new MockBuildEngine();
            var task        = new PublishArtifactsInManifest
            {
                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" },
                        { "Internal", "true" }
                    }),
                },
                BuildEngine = buildEngine
            };

            await task.ParseTargetFeedConfigAsync();

            Assert.True(!task.Log.HasLoggedErrors);
        }
Exemple #3
0
        public void ConstructV3PublishingTask()
        {
            var manifestFullPath = TestInputs.GetFullPath(Path.Combine("Manifests", "SampleV3.xml"));

            var buildEngine = new MockBuildEngine();
            var task        = new PublishArtifactsInManifest()
            {
                BuildEngine    = buildEngine,
                TargetChannels = GeneralTestingChannelId
            };

            // Dependency Injection setup
            var collection = new ServiceCollection()
                             .AddSingleton <IFileSystem, FileSystem>()
                             .AddSingleton <IBuildModelFactory, BuildModelFactory>();

            task.ConfigureServices(collection);
            using var provider = collection.BuildServiceProvider();

            // Act and Assert
            task.InvokeExecute(provider);

            var which = task.WhichPublishingTask(manifestFullPath);

            which.Should().BeOfType <PublishArtifactsInManifestV3>();
        }
        public void FeedConfigParserTests1()
        {
            var buildEngine = new MockBuildEngine();
            var task        = new PublishArtifactsInManifest
            {
                // Create a single ITaskItem for a simple feed config, then parse to FeedConfigs and
                // check the expected values.
                TargetFeedConfig = new TaskItem[]
                {
                    new TaskItem("FOOPACKAGES", new Dictionary <string, string> {
                        { "TargetUrl", BlobFeedUrl },
                        { "Token", RandomToken },
                        { "Type", "AzDoNugetFeed" }
                    }),
                },
                BuildEngine = buildEngine
            };

            task.ParseTargetFeedConfig();
            Assert.False(task.Log.HasLoggedErrors);

            // This will have set the feed configs.
            Assert.Collection(task.FeedConfigs,
                              configList =>
            {
                Assert.Equal("FOOPACKAGES", configList.Key);
                Assert.Collection(configList.Value, config =>
                {
                    Assert.Equal(RandomToken, config.FeedKey);
                    Assert.Equal(BlobFeedUrl, config.TargetFeedURL);
                    Assert.Equal(FeedType.AzDoNugetFeed, config.Type);
                    Assert.Equal(AssetSelection.All, config.AssetSelection);
                });
            });
        }
        public void FeedConfigParserTests4()
        {
            var buildEngine = new MockBuildEngine();
            var task        = new PublishArtifactsInManifest
            {
                TargetFeedConfig = new TaskItem[]
                {
                    new TaskItem("FOOPACKAGES", new Dictionary <string, string> {
                        { "TargetUrl", BlobFeedUrl },
                        { "Token", RandomToken },
                        { "Type", "AZURESTORAGEFEED" },
                        { "AssetSelection", "SHIPPINGONLY" }
                    }),
                },
                BuildEngine = buildEngine
            };

            task.ParseTargetFeedConfig();

            // This will have set the feed configs.
            Assert.Collection(task.FeedConfigs,
                              configList =>
            {
                Assert.Equal("FOOPACKAGES", configList.Key);
                Assert.Collection(configList.Value, config =>
                {
                    Assert.Equal(RandomToken, config.FeedKey);
                    Assert.Equal(BlobFeedUrl, config.TargetFeedURL);
                    Assert.Equal(FeedType.AzureStorageFeed, config.Type);
                    Assert.Equal(AssetSelection.ShippingOnly, config.AssetSelection);
                });
            });
        }
Exemple #6
0
        public async Task StreamComparisonTestsAsync(string streamA, string streamB, int[] maxStreamABytesReturnedEachCall, int[] maxStreamBBytesReturnedEachCall, int bufferSize)
        {
            byte[] streamABytes = Convert.FromBase64String(streamA);
            byte[] streamBBytes = Convert.FromBase64String(streamB);

            FakeStream fakeStreamA = new FakeStream(streamABytes, maxStreamABytesReturnedEachCall);
            FakeStream fakeStreamB = new FakeStream(streamBBytes, maxStreamBBytesReturnedEachCall);

            Assert.Equal(streamA == streamB, await PublishArtifactsInManifest.CompareStreamsAsync(fakeStreamA, fakeStreamB, bufferSize));
        }
Exemple #7
0
        public async Task StableAssetCheck1Async(string assetVersion, bool isIsolatedFeed, bool shouldError, bool skipChecks = false)
        {
            var buildEngine = new MockBuildEngine();
            var task        = new PublishArtifactsInManifest
            {
                SkipSafetyChecks = skipChecks,
                TargetFeedConfig = new Microsoft.Build.Utilities.TaskItem[]
                {
                    new Microsoft.Build.Utilities.TaskItem("PACKAGE", new Dictionary <string, string> {
                        { "TargetUrl", BlobFeedUrl },
                        { "Token", RandomToken },
                        { "Type", "AZURESTORAGEFEED" },
                        { "AssetSelection", "SHIPPINGONLY" },
                        { "Internal", "false" },
                        // Feed is not isolated
                        { "Isolated", isIsolatedFeed.ToString() }
                    })
                },
                BuildEngine = buildEngine
            };

            const string packageId = "Foo.Package";

            BuildModel buildModel = new BuildModel(new BuildIdentity())
            {
                Artifacts = new ArtifactSet
                {
                    Blobs    = new List <BlobArtifactModel>(),
                    Packages = new List <PackageArtifactModel>
                    {
                        new PackageArtifactModel()
                        {
                            Id      = packageId,
                            Version = assetVersion
                        }
                    }
                }
            };

            await task.ParseTargetFeedConfigAsync();

            Assert.False(task.Log.HasLoggedErrors);

            task.SplitArtifactsInCategories(buildModel);
            Assert.False(task.Log.HasLoggedErrors);

            task.CheckForStableAssets();
            Assert.Equal(shouldError, task.Log.HasLoggedErrors);
            if (shouldError)
            {
                Assert.Contains(buildEngine.BuildErrorEvents, e => e.Message.Equals($"Package '{packageId}' has stable version '{assetVersion}' but is targeted at a non-isolated feed '{BlobFeedUrl}'"));
            }
        }
Exemple #8
0
        public void ConstructV3PublishingTask()
        {
            var manifestFullPath = TestInputs.GetFullPath(Path.Combine("Manifests", "SampleV3.xml"));

            var buildEngine = new MockBuildEngine();
            var task        = new PublishArtifactsInManifest()
            {
                BuildEngine    = buildEngine,
                TargetChannels = GeneralTestingChannelId
            };

            var which = task.WhichPublishingTask(manifestFullPath);

            which.Should().BeOfType <PublishArtifactsInManifestV3>();
        }
Exemple #9
0
        public void ConstructV3PublishingTask()
        {
            var testInputs       = Path.Combine(Path.GetDirectoryName(typeof(PublishArtifactsInManifestTests).Assembly.Location), "TestInputs", "Manifests");
            var manifestFullPath = Path.Combine(testInputs, "SampleV3.xml");

            var buildEngine = new MockBuildEngine();
            var task        = new PublishArtifactsInManifest()
            {
                BuildEngine    = buildEngine,
                TargetChannels = GeneralTestingChannelId
            };

            var which = task.WhichPublishingTask(manifestFullPath);

            Assert.IsType <PublishArtifactsInManifestV3>(which);
        }
        public void FeedConfigParserTests3()
        {
            var buildEngine = new MockBuildEngine();
            var task        = new PublishArtifactsInManifest
            {
                TargetFeedConfig = new TaskItem[]
                {
                    new TaskItem("FOOPACKAGES", new Dictionary <string, string> {
                        { "TargetUrl", string.Empty },
                        { "Token", string.Empty },
                        { "Type", string.Empty }
                    }),
                },
                BuildEngine = buildEngine
            };

            task.ParseTargetFeedConfig();
            Assert.True(task.Log.HasLoggedErrors);
            Assert.Contains(buildEngine.BuildErrorEvents, e => e.Message.Equals("Invalid FeedConfig entry. TargetURL='' Type='' Token=''"));
        }
        public void FeedConfigParserTests2()
        {
            var buildEngine = new MockBuildEngine();
            var task        = new PublishArtifactsInManifest
            {
                TargetFeedConfig = new TaskItem[]
                {
                    new TaskItem("FOOPACKAGES", new Dictionary <string, string> {
                        { "TargetUrl", BlobFeedUrl },
                        { "Token", RandomToken },
                        { "Type", "MyUnknownFeedType" }
                    }),
                },
                BuildEngine = buildEngine
            };

            task.ParseTargetFeedConfig();
            Assert.True(task.Log.HasLoggedErrors);
            Assert.Contains(buildEngine.BuildErrorEvents, e => e.Message.Equals("Invalid feed config type 'MyUnknownFeedType'. Possible values are: AzDoNugetFeed, AzureStorageFeed"));
        }
Exemple #12
0
        public async Task FeedConfigParserTests4Async()
        {
            var buildEngine = new MockBuildEngine();
            var task        = new PublishArtifactsInManifest
            {
                TargetFeedConfig = new Microsoft.Build.Utilities.TaskItem[]
                {
                    new Microsoft.Build.Utilities.TaskItem("FOOPACKAGES", 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("FOOPACKAGES", 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);
                });
            });
        }