public async void GettingSameStatusTwiceReportsOnce()
        {
            var returnedStatus = EdgeDeploymentStatus.Success("Successfully deployed");
            var edgeDefinition = new EdgeDeploymentDefinition("v1", "EdgeDeployment", new V1ObjectMeta(name: ResourceName), new List <KubernetesModule>(), null);
            var response       = new HttpOperationResponse <object>()
            {
                Body     = edgeDefinition,
                Response = new HttpResponseMessage(HttpStatusCode.OK)
            };

            // DeployModules returns a status, confirm this is what is reported.
            var controller = Mock.Of <IEdgeDeploymentController>();

            Mock.Get(controller).Setup(c => c.DeployModulesAsync(It.IsAny <ModuleSet>(), It.IsAny <ModuleSet>()))
            .ReturnsAsync(returnedStatus);

            var client = Mock.Of <IKubernetes>();

            Mock.Get(client).Setup(c => c.ReplaceNamespacedCustomObjectStatusWithHttpMessagesAsync(It.IsAny <object>(), Constants.EdgeDeployment.Group, Constants.EdgeDeployment.Version, DeviceNamespace, Constants.EdgeDeployment.Plural, It.IsAny <string>(), null, It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            var edgeOperator = new EdgeDeploymentOperator(
                ResourceName,
                DeviceNamespace,
                client,
                controller);

            await edgeOperator.EdgeDeploymentOnEventHandlerAsync(WatchEventType.Added, edgeDefinition);

            await edgeOperator.EdgeDeploymentOnEventHandlerAsync(WatchEventType.Modified, edgeDefinition);

            Mock.Get(controller).Verify(c => c.DeployModulesAsync(It.IsAny <ModuleSet>(), It.IsAny <ModuleSet>()), Times.Exactly(2));
            Mock.Get(client).Verify(c => c.ReplaceNamespacedCustomObjectStatusWithHttpMessagesAsync(It.IsAny <object>(), Constants.EdgeDeployment.Group, Constants.EdgeDeployment.Version, DeviceNamespace, Constants.EdgeDeployment.Plural, It.IsAny <string>(), null, It.IsAny <CancellationToken>()), Times.Once);
        }
        public async void NoProcessingDeploymentIfEdgeDeploymentNameMismatch()
        {
            var edgeDefinition = new EdgeDeploymentDefinition("v1", "EdgeDeployment", new V1ObjectMeta(name: "not-the-resource-name"), new List <KubernetesModule>(), null);

            var client     = Mock.Of <IKubernetes>();
            var controller = Mock.Of <IEdgeDeploymentController>();

            var edgeOperator = new EdgeDeploymentOperator(
                ResourceName,
                DeviceNamespace,
                client,
                controller);

            await edgeOperator.EdgeDeploymentOnEventHandlerAsync(WatchEventType.Added, edgeDefinition);

            Mock.Get(controller).VerifyAll();
            Mock.Get(client).VerifyAll();
        }
Ejemplo n.º 3
0
        public async void PurgeModulesOnDelete()
        {
            var edgeDefinition = new EdgeDeploymentDefinition("v1", "EdgeDeployment", new V1ObjectMeta(name: ResourceName), new List <KubernetesModule>(), null);

            var client     = Mock.Of <IKubernetes>();
            var controller = Mock.Of <IEdgeDeploymentController>(c => c.PurgeModulesAsync() == Task.CompletedTask);

            var edgeOperator = new EdgeDeploymentOperator(
                ResourceName,
                DeviceNamespace,
                client,
                controller);

            await edgeOperator.EdgeDeploymentOnEventHandlerAsync(WatchEventType.Deleted, edgeDefinition);

            Mock.Get(controller).VerifyAll();
            Mock.Get(client).VerifyAll();
        }
        public async void WhatDeployModulesReturnsIsWhatIsReported()
        {
            var returnedStatus = EdgeDeploymentStatus.Success("Successfully deployed");
            Option <EdgeDeploymentStatus> reportedStatus = Option.None <EdgeDeploymentStatus>();
            var edgeDefinition = new EdgeDeploymentDefinition("v1", "EdgeDeployment", new V1ObjectMeta(name: ResourceName), new List <KubernetesModule>(), null);
            var response       = new HttpOperationResponse <object>()
            {
                Body     = edgeDefinition,
                Response = new HttpResponseMessage(HttpStatusCode.OK)
            };

            // DeployModules returns a status, confirm this is what is reported.
            var controller = Mock.Of <IEdgeDeploymentController>();

            Mock.Get(controller).Setup(c => c.DeployModulesAsync(It.IsAny <ModuleSet>(), It.IsAny <ModuleSet>()))
            .ReturnsAsync(returnedStatus);

            var client = Mock.Of <IKubernetes>();

            Mock.Get(client).Setup(c => c.ReplaceNamespacedCustomObjectStatusWithHttpMessagesAsync(It.IsAny <object>(), Constants.EdgeDeployment.Group, Constants.EdgeDeployment.Version, DeviceNamespace, Constants.EdgeDeployment.Plural, It.IsAny <string>(), null, It.IsAny <CancellationToken>()))
            .Callback((object o, string group, string version, string _namespace, string plural, string name, Dictionary <string, List <string> > headers, CancellationToken token) =>
            {
                Assert.True(o is JObject);
                EdgeDeploymentDefinition e = ((JObject)o).ToObject <EdgeDeploymentDefinition>();
                reportedStatus             = e.Status;
            })
            .ReturnsAsync(response);

            var edgeOperator = new EdgeDeploymentOperator(
                ResourceName,
                DeviceNamespace,
                client,
                controller);

            await edgeOperator.EdgeDeploymentOnEventHandlerAsync(WatchEventType.Added, edgeDefinition);

            Assert.True(reportedStatus.HasValue);
            Assert.Equal(returnedStatus, reportedStatus.OrDefault());

            Mock.Get(controller).VerifyAll();
            Mock.Get(client).VerifyAll();
        }
Ejemplo n.º 5
0
        public async void StatusIsFailedWhenUnexpectedExceptionIsThrown()
        {
            Exception                     controllerException = new Exception(ExceptionMessage);
            EdgeDeploymentStatus          expectedStatus      = EdgeDeploymentStatus.Failure(controllerException);
            Option <EdgeDeploymentStatus> reportedStatus      = Option.None <EdgeDeploymentStatus>();
            var edgeDefinition = new EdgeDeploymentDefinition("v1", "EdgeDeployment", new V1ObjectMeta(name: ResourceName), new List <KubernetesModule>(), null);
            var response       = new HttpOperationResponse <object>()
            {
                Body     = edgeDefinition,
                Response = new HttpResponseMessage(HttpStatusCode.OK)
            };

            var controller = Mock.Of <IEdgeDeploymentController>();

            Mock.Get(controller).Setup(c => c.DeployModulesAsync(It.IsAny <ModuleSet>(), It.IsAny <ModuleSet>()))
            .ThrowsAsync(controllerException);

            var client = Mock.Of <IKubernetes>();

            Mock.Get(client).Setup(c => c.ReplaceNamespacedCustomObjectStatusWithHttpMessagesAsync(It.IsAny <object>(), Constants.EdgeDeployment.Group, Constants.EdgeDeployment.Version, DeviceNamespace, Constants.EdgeDeployment.Plural, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, It.IsAny <CancellationToken>()))
            .Callback((object o, string group, string version, string _namespace, string plural, string name, string dryRun, string fieldmanager, Dictionary <string, List <string> > headers, CancellationToken token) =>
            {
                Assert.True(o is JObject);
                EdgeDeploymentDefinition e = ((JObject)o).ToObject <EdgeDeploymentDefinition>();
                reportedStatus             = e.Status;
            })
            .ReturnsAsync(response);

            var edgeOperator = new EdgeDeploymentOperator(
                ResourceName,
                DeviceNamespace,
                client,
                controller);

            Exception ex = await Assert.ThrowsAsync <Exception>(() => edgeOperator.EdgeDeploymentOnEventHandlerAsync(WatchEventType.Added, edgeDefinition));

            Assert.Equal(controllerException, ex);
            Assert.True(reportedStatus.HasValue);
            Assert.Equal(expectedStatus, reportedStatus.OrDefault());
            Mock.Get(controller).VerifyAll();
            Mock.Get(client).VerifyAll();
        }