Esempio n. 1
0
        public async Task ImageNotFoundUnitTest()
        {
            const string Name = "non-existing-image-name";

            using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(15)))
            {
                var images = new Mock <IImageOperations>();
                // ImagesCreateParameters parameters, AuthConfig authConfig, IProgress<JSONMessage> progress, CancellationToken cancellationToken = default(CancellationToken)
                images.Setup(
                    m => m.CreateImageAsync(
                        It.IsAny <ImagesCreateParameters>(),
                        It.IsAny <AuthConfig>(),
                        It.IsAny <IProgress <JSONMessage> >(),
                        It.IsAny <CancellationToken>()))
                .Throws(new DockerApiException(HttpStatusCode.NotFound, "FakeResponseBody"));

                var dockerClient = new Mock <IDockerClient>();
                dockerClient.SetupGet(c => c.Images).Returns(images.Object);

                var      config      = new CombinedDockerConfig(Name, new CreateContainerParameters(), NoAuth);
                ICommand pullCommand = new PullCommand(dockerClient.Object, config);

                await Assert.ThrowsAsync <ImageNotFoundException>(() => pullCommand.ExecuteAsync(cts.Token));
            }
        }
Esempio n. 2
0
        public async Task ImageNotFoundTest()
        {
            const string Image = "non-existing-image:latest";
            const string Name  = "non-existing-image-name";

            try
            {
                using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(15)))
                {
                    await DockerHelper.Client.CleanupContainerAsync(Name, Image);

                    var config = new CombinedDockerConfig(Image, new CreateContainerParameters(), NoAuth);

                    ICommand pullCommand = new PullCommand(DockerHelper.Client, config);
                    await Assert.ThrowsAsync <ImageNotFoundException>(() => pullCommand.ExecuteAsync(cts.Token));
                }
            }
            finally
            {
                await DockerHelper.Client.CleanupContainerAsync(Name, Image);
            }
        }
Esempio n. 3
0
        public async Task PullValidImages(string testFullImage, string image, string tag)
        {
            // Arrange
            string testImage = string.Empty;
            string testTag   = string.Empty;
            var    auth      = new AuthConfig();
            var    client    = new Mock <IDockerClient>();
            var    images    = new Mock <IImageOperations>();

            images.Setup(
                i => i.CreateImageAsync(
                    It.IsAny <ImagesCreateParameters>(),
                    It.IsAny <AuthConfig>(),
                    It.IsAny <IProgress <JSONMessage> >(),
                    It.IsAny <CancellationToken>()))
            .Callback <ImagesCreateParameters, AuthConfig, IProgress <JSONMessage>, CancellationToken>(
                (icp, a, p, t) =>
            {
                testImage = icp.FromImage;
                testTag   = icp.Tag;
            })
            .Returns(TaskEx.Done);
            client.SetupGet(c => c.Images).Returns(images.Object);

            var config = new CombinedDockerConfig(testFullImage, new CreateContainerParameters(), Option.Some(auth));

            // Act
            var command = new PullCommand(client.Object, config);

            await command.ExecuteAsync(CancellationToken.None);

            // Assert
            client.VerifyAll();
            images.VerifyAll();

            Assert.Equal(image, testImage);
            Assert.Equal(tag, testTag);
        }