Пример #1
0
        public async Task TestLoadAsync()
        {
            DockerClient testDockerClient =
                new DockerClient(
                    subcommand =>
            {
                Assert.AreEqual(new List <string> {
                    "load"
                }, subcommand);
                return(mockProcessBuilder);
            });

            Mock.Get(mockProcess).Setup(m => m.WaitFor()).Returns(0);

            // Captures stdin.
            MemoryStream byteArrayOutputStream = new MemoryStream();

            Mock.Get(mockProcess).Setup(m => m.GetOutputStream()).Returns(byteArrayOutputStream);

            // Simulates stdout.
            Mock.Get(mockProcess).Setup(m => m.GetInputStream()).Returns(new MemoryStream(Encoding.UTF8.GetBytes("output")));

            string output = await testDockerClient.LoadAsync(imageTarball).ConfigureAwait(false);

            Assert.AreEqual(
                "fib", Encoding.UTF8.GetString(byteArrayOutputStream.ToArray()));
            Assert.AreEqual("output", output);
        }
Пример #2
0
        public async Task <BuildResult> CallAsync()
        {
            await pullAndCacheBaseImageLayersStep.GetFuture().ConfigureAwait(false);

            await buildAndCacheApplicationLayersStep.GetFuture().ConfigureAwait(false);

            await buildImageStep.GetFuture().ConfigureAwait(false);

            buildConfiguration
            .GetEventHandlers()
            .Dispatch(LogEvent.Progress(Resources.LoadDockerStepDescription));

            using (progressEventDispatcherFactory.Create(Resources.LoadDockerStepDescription, 1))
            {
                Image image = await buildImageStep.GetFuture().ConfigureAwait(false);

                IImageReference targetImageReference =
                    buildConfiguration.GetTargetImageConfiguration().GetImage();

                // Load the image to docker daemon.
                buildConfiguration
                .GetEventHandlers()
                .Dispatch(
                    LogEvent.Debug(await dockerClient.LoadAsync(new ImageTarball(image, targetImageReference)).ConfigureAwait(false)));

                // Tags the image with all the additional tags, skipping the one 'docker load' already loaded.
                foreach (string tag in buildConfiguration.GetAllTargetImageTags())
                {
                    if (tag.Equals(targetImageReference.GetTag(), StringComparison.Ordinal))
                    {
                        continue;
                    }

                    ImageReference taggedImageReference = targetImageReference.WithTag(tag);
                    await dockerClient.TagAsync(targetImageReference, taggedImageReference).ConfigureAwait(false);
                }

                return(await BuildResult.FromImageAsync(image, buildConfiguration.GetTargetFormat()).ConfigureAwait(false));
            }
        }
Пример #3
0
        public async Task TestLoad_stdinFailAsync()
        {
            DockerClient testDockerClient = new DockerClient(_ => mockProcessBuilder);

            Mock.Get(mockProcess)
            .Setup(m =>
                   m.GetOutputStream().WriteAsync(It.IsAny <ReadOnlyMemory <byte> >(), It.IsAny <CancellationToken>()))
            .Throws <IOException>();

            Mock.Get(mockProcess).Setup(m => m.GetErrorReader()).Returns(new StringReader("error"));

            try
            {
                await testDockerClient.LoadAsync(imageTarball).ConfigureAwait(false);

                Assert.Fail("Write should have failed");
            }
            catch (IOException ex)
            {
                Assert.AreEqual("'docker load' command failed with error: error", ex.Message);
            }
        }
Пример #4
0
        public async Task TestLoad_stdinFail_stderrFailAsync()
        {
            DockerClient testDockerClient    = new DockerClient(_ => mockProcessBuilder);
            IOException  expectedIOException = new IOException();

            Mock.Get(mockProcess)
            .Setup(m =>
                   m.GetOutputStream().WriteAsync(It.IsAny <ReadOnlyMemory <byte> >(), It.IsAny <CancellationToken>()))
            .Throws(expectedIOException);

            Mock.Get(mockProcess).Setup(m => m.GetErrorReader().ReadToEnd()).Throws <IOException>();
            try
            {
                await testDockerClient.LoadAsync(imageTarball).ConfigureAwait(false);

                Assert.Fail("Write should have failed");
            }
            catch (IOException ex)
            {
                Assert.AreSame(expectedIOException, ex);
            }
        }
Пример #5
0
        public async Task TestLoad_stdoutFailAsync()
        {
            DockerClient testDockerClient = new DockerClient(_ => mockProcessBuilder);

            Mock.Get(mockProcess).Setup(m => m.WaitFor()).Returns(1);

            Mock.Get(mockProcess).Setup(m => m.GetOutputStream()).Returns(Stream.Null);

            Mock.Get(mockProcess).Setup(m => m.GetInputStream()).Returns(new MemoryStream(Encoding.UTF8.GetBytes("ignored")));

            Mock.Get(mockProcess).Setup(m => m.GetErrorStream()).Returns(new MemoryStream(Encoding.UTF8.GetBytes("error")));

            try
            {
                await testDockerClient.LoadAsync(imageTarball).ConfigureAwait(false);

                Assert.Fail("Process should have failed");
            }
            catch (IOException ex)
            {
                Assert.AreEqual("'docker load' command failed with output: error", ex.Message);
            }
        }