Skip to content

Commit bccbcc7

Browse files
committed
tests
1 parent 7653525 commit bccbcc7

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

test/Docker.Testify/DockerSetup.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Diagnostics;
6+
using System.IO;
67
using System.Linq;
78
using System.Net.NetworkInformation;
89
using System.Runtime.InteropServices;
@@ -55,8 +56,7 @@ public async Task StartContainer()
5556
hostCfg.PortBindings = new Dictionary<string, IList<PortBinding>>();
5657
hostCfg.PortBindings.Add($"{InternalPort}/tcp", new PortBinding[] { pb });
5758

58-
//await docker.Images.PullImageAsync(new ImagesPullParameters() { Parent = ImageName, Tag = ImageTag }, null);
59-
Process.Start("docker", $"pull {ImageName}:{ImageTag}").WaitForExit();
59+
await PullImage(ImageName, ImageTag);
6060

6161
var container = await docker.Containers.CreateContainerAsync(new CreateContainerParameters()
6262
{
@@ -100,6 +100,25 @@ public async Task StartContainer()
100100
}
101101
}
102102

103+
public async Task PullImage(string name, string tag)
104+
{
105+
var images = docker.Images.ListImagesAsync(new ImagesListParameters()).Result;
106+
var exists = images
107+
.Where(x => x.RepoTags != null)
108+
.Any(x => x.RepoTags.Contains($"{name}:{tag}"));
109+
110+
if (exists)
111+
return;
112+
113+
var stream = await docker.Images.PullImageAsync(new ImagesPullParameters() { Parent = name, Tag = tag }, null);
114+
115+
using (StreamReader reader = new StreamReader(stream))
116+
{
117+
while (!reader.EndOfStream)
118+
Debug.WriteLine(reader.ReadLine());
119+
}
120+
}
121+
103122
public void Dispose()
104123
{
105124
docker.Containers.KillContainerAsync(containerId, new ContainerKillParameters()).Wait();

0 commit comments

Comments
 (0)