internal async Task <DockerContainer> StartContainerAsync(string imageId, Action <StartContainerOptions> configureOptions = null) { StartContainerOptions options = null; if (configureOptions != null) { options = new StartContainerOptions(); configureOptions(options); options.Validate(); } var cmd = DockerCommands.Image.RunContainer(imageId, options); var command = _commandFactory.RunCommand(cmd, _client.WorkingDirectory, new CancellationToken()); await command.Task; var success = command.Result.Success; if (!success) { throw new DockerCommandException(cmd, command.GetOutputAndErrorLines().ToList()); } var output = command.GetOutputAndErrorLines(); var firstLine = output.FirstOrDefault(); if (string.IsNullOrWhiteSpace(firstLine) || firstLine.Length < 12) { throw new DockerCommandUnexpectedOutputException(cmd, command.GetOutputAndErrorLines().ToList()); } var containerId = firstLine.Substring(0, 12); return(new DockerContainer(_client, _commandFactory, containerId, options?.DockerPortMappings)); }
public void ValidateWhenMemoryLimitValid(int memLimit) { // Arrange var sut = new StartContainerOptions(); sut.WithMemoryLimit(memLimit); // Act/Assert Assert.DoesNotThrow(() => sut.Validate()); }
public void ValidateWhenCpuCountAtMaxAllowed() { // Arrange var sut = new StartContainerOptions(); sut.WithCpuLimit(Environment.ProcessorCount); // Act/Assert Assert.DoesNotThrow(() => sut.Validate()); }
public void ValidateWhenCpuCountValidAboveZero() { // Arrange var sut = new StartContainerOptions(); sut.WithCpuLimit(0.1m); // Act/Assert Assert.DoesNotThrow(() => sut.Validate()); }
public void ValidateWhenCpuCountTooLow(decimal cpuCount) { // Arrange var sut = new StartContainerOptions(); sut.WithCpuLimit(cpuCount); // Act var exception = Assert.Catch(() => sut.Validate()); // Assert exception.Should().BeOfType <ArgumentException>(); }
public void ValidateWhenCpuCountTooHigh() { // Arrange var sut = new StartContainerOptions(); sut.WithCpuLimit(Environment.ProcessorCount + 1); // Act var exception = Assert.Catch(() => sut.Validate()); // Assert exception.Should().BeOfType <ArgumentException>(); }