public async Task WatchCustomResourceDefinitionAsync_ValidatesArguments_Async() { var protocol = new KubernetesProtocol(new DummyHandler(), this.loggerFactory.CreateLogger <KubernetesProtocol>(), this.loggerFactory); await Assert.ThrowsAsync <ArgumentNullException>("value", () => protocol.WatchCustomResourceDefinitionAsync(null, (eventType, result) => Task.FromResult(WatchResult.Continue), default)).ConfigureAwait(false); await Assert.ThrowsAsync <ValidationException>(() => protocol.WatchCustomResourceDefinitionAsync(new V1CustomResourceDefinition(), (eventType, result) => Task.FromResult(WatchResult.Continue), default)).ConfigureAwait(false); await Assert.ThrowsAsync <ValidationException>(() => protocol.WatchCustomResourceDefinitionAsync(new V1CustomResourceDefinition() { Metadata = new V1ObjectMeta() }, (eventType, result) => Task.FromResult(WatchResult.Continue), default)).ConfigureAwait(false); await Assert.ThrowsAsync <ArgumentNullException>("eventHandler", () => protocol.WatchCustomResourceDefinitionAsync(new V1CustomResourceDefinition() { Metadata = new V1ObjectMeta() { Name = "test" } }, null, default)).ConfigureAwait(false); }
public async Task WatchCustomResourceDefinitionAsync_EmptyContent_Completes_Async() { var handler = new DummyHandler(); handler.Responses.Enqueue( new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new WatchHttpContent( new StringContent(string.Empty)), }); Collection <(WatchEventType, V1CustomResourceDefinition)> events = new Collection <(WatchEventType, V1CustomResourceDefinition)>(); var protocol = new KubernetesProtocol(handler, this.loggerFactory.CreateLogger <KubernetesProtocol>(), this.loggerFactory); var result = await protocol.WatchCustomResourceDefinitionAsync( new V1CustomResourceDefinition() { Metadata = new V1ObjectMeta(name: "crd", namespaceProperty: "default", resourceVersion: "1"), }, (eventType, result) => { events.Add((eventType, result)); return(Task.FromResult(WatchResult.Continue)); }, default).ConfigureAwait(false); Assert.Equal(WatchExitReason.ServerDisconnected, result); Assert.Empty(events); Assert.Collection( handler.Requests, r => { Assert.Equal(new Uri("http://localhost/apis/apiextensions.k8s.io/v1/customresourcedefinitions?fieldSelector=metadata.name%3Dcrd&resourceVersion=1&watch=true"), r.RequestUri); }); }