Skip to content

Commit 386bfd6

Browse files
authored
rebased (#529)
1 parent 2ae4c63 commit 386bfd6

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Docker.DotNet/Endpoints/ContainerOperations.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ internal class ContainerOperations : IContainerOperations
2020
throw new DockerContainerNotFoundException(statusCode, responseBody);
2121
}
2222
};
23+
internal static readonly ApiResponseErrorHandlingDelegate NoSuchImageHandler = (statusCode, responseBody) =>
24+
{
25+
if (statusCode == HttpStatusCode.NotFound)
26+
{
27+
throw new DockerImageNotFoundException(statusCode, responseBody);
28+
}
29+
};
2330

2431
private readonly DockerClient _client;
2532

@@ -55,7 +62,7 @@ internal ContainerOperations(DockerClient client)
5562
}
5663

5764
var data = new JsonRequestContent<CreateContainerParameters>(parameters, this._client.JsonSerializer);
58-
var response = await this._client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, "containers/create", qs, data, cancellationToken).ConfigureAwait(false);
65+
var response = await this._client.MakeRequestAsync(new[] { NoSuchImageHandler }, HttpMethod.Post, "containers/create", qs, data, cancellationToken).ConfigureAwait(false);
5966
return this._client.JsonSerializer.DeserializeObject<CreateContainerResponse>(response.Body);
6067
}
6168

test/Docker.DotNet.Tests/IContainerOperationsTests.cs

+12
Original file line numberDiff line numberDiff line change
@@ -808,5 +808,17 @@ public async Task WaitContainerAsync_TokenIsCancelled_OperationCancelledExceptio
808808
Assert.InRange(stopWatch.Elapsed, delay.Subtract(tolerance), delay.Add(tolerance));
809809
Assert.True(waitContainerTask.IsCanceled);
810810
}
811+
812+
[Fact]
813+
public async Task CreateImageAsync_NonexistantImage_ThrowsDockerImageNotFoundException()
814+
{
815+
var parameters = new CreateContainerParameters
816+
{
817+
Image = "no-such-image-ytfghbkufhresdhtrjygvb",
818+
};
819+
Func<Task> op = async () => await _dockerClient.Containers.CreateContainerAsync(parameters);
820+
821+
await Assert.ThrowsAsync<DockerImageNotFoundException>(op);
822+
}
811823
}
812824
}

0 commit comments

Comments
 (0)