public async Task CreatePodAsync_CapturesKubernetesError_Async(HttpStatusCode statusCode) { const string status = @"{""kind"":""Status"",""apiVersion"":""v1"",""metadata"":{},""status"":""Failure"",""message"":""pods 'waitforpodrunning-integrationtest-async' already exists"",""reason"":""AlreadyExists"",""details"":{ ""name"":""waitforpodrunning-integrationtest-async"",""kind"":""pods""},""code"":409}"; var pod = new V1Pod() { Metadata = new V1ObjectMeta() { NamespaceProperty = "default" } }; var protocol = new Mock <IKubernetesProtocol>(MockBehavior.Strict); protocol .Setup(p => p.CreateNamespacedPodWithHttpMessagesAsync(pod, pod.Metadata.NamespaceProperty, null, null, null, null, default)) .ThrowsAsync( new HttpOperationException() { Response = new HttpResponseMessageWrapper( new HttpResponseMessage(statusCode), status), }); protocol.Setup(p => p.Dispose()).Verifiable(); using (var client = new KubernetesClient(protocol.Object, KubernetesOptions.Default, NullLogger <KubernetesClient> .Instance, NullLoggerFactory.Instance)) { var ex = await Assert.ThrowsAsync <KubernetesException>(() => client.CreatePodAsync(pod, default)).ConfigureAwait(false); Assert.Equal("pods 'waitforpodrunning-integrationtest-async' already exists", ex.Message); Assert.NotNull(ex.Status); } }
[InlineData(@"{""kind"":""Status"", ""apiVersion"":""v1beta1"", ""message"":""""}")] // Empty message public async Task CreatePodAsync_InvalidKubernetesError_Async(string statusJson) { var pod = new V1Pod() { Metadata = new V1ObjectMeta() { NamespaceProperty = "default" } }; var protocol = new Mock <IKubernetesProtocol>(MockBehavior.Strict); protocol .Setup(p => p.CreateNamespacedPodWithHttpMessagesAsync(pod, pod.Metadata.NamespaceProperty, null, null, null, null, default)) .ThrowsAsync( new HttpOperationException() { Response = new HttpResponseMessageWrapper( new HttpResponseMessage(HttpStatusCode.UnprocessableEntity), statusJson), }); protocol.Setup(p => p.Dispose()).Verifiable(); using (var client = new KubernetesClient(protocol.Object, KubernetesOptions.Default, NullLogger <KubernetesClient> .Instance, NullLoggerFactory.Instance)) { await Assert.ThrowsAsync <HttpOperationException>(() => client.CreatePodAsync(pod, default)).ConfigureAwait(false); } }
public async Task CreatePodAsync_ValidatesArguments_Async() { var protocol = new Mock <IKubernetesProtocol>(MockBehavior.Strict); protocol.Setup(p => p.Dispose()).Verifiable(); using (var client = new KubernetesClient(protocol.Object, KubernetesOptions.Default, NullLogger <KubernetesClient> .Instance, NullLoggerFactory.Instance)) { await Assert.ThrowsAsync <ArgumentNullException>("value", () => client.CreatePodAsync(null, default)).ConfigureAwait(false); await Assert.ThrowsAsync <ValidationException>(() => client.CreatePodAsync(new V1Pod(), default)).ConfigureAwait(false); await Assert.ThrowsAsync <ValidationException>(() => client.CreatePodAsync(new V1Pod() { Metadata = new V1ObjectMeta() }, default)).ConfigureAwait(false); } }