public async Task ShouldRunCommandWhenContainerStarts() { // act var(stdout, _) = await Container.ExecuteCommand( PlatformSpecific.ShellCommand( PlatformSpecific.IfExistsThenFormat($"{_fileTouchedByCommand}", $"{PlatformSpecific.Echo} 1"))); // assert Assert.Equal("1", stdout.TrimEndNewLine()); }
public GenericContainerFixture() { HostPathBinding = new KeyValuePair <string, string>(Directory.GetCurrentDirectory(), PlatformSpecific.BindPath); FileTouchedByCommand = PlatformSpecific.TouchedFilePath; WorkingDirectory = PlatformSpecific.WorkingDirectory; Container = new ContainerBuilder <GenericContainer>() .ConfigureHostConfiguration(builder => builder.AddInMemoryCollection()) .ConfigureAppConfiguration((context, builder) => builder.AddInMemoryCollection()) .ConfigureDockerImageName(PlatformSpecific.TinyDockerImage) .ConfigureLogging(builder => builder.AddConsole()) .ConfigureContainer((context, container) => { container.Labels.Add(CustomLabel.Key, CustomLabel.Value); container.Env[InjectedEnvVar.Key] = InjectedEnvVar.Value; container.ExposedPorts.Add(ExposedPort); /* * to do something like `docker run -p 2345:34567 alpine:latest`, * both expose port and port binding must be set */ container.ExposedPorts.Add(PortBinding.Key); container.PortBindings.Add(PortBinding.Key, PortBinding.Value); container.BindMounts.Add(new Bind { HostPath = HostPathBinding.Key, ContainerPath = HostPathBinding.Value, AccessMode = AccessMode.ReadOnly }); container.WorkingDirectory = WorkingDirectory; container.Command = PlatformSpecific.ShellCommand( $"{PlatformSpecific.Touch} {FileTouchedByCommand}; {PlatformSpecific.Shell}") .ToList(); }) .Build(); DockerClient = new DockerClientFactory().Create(); }