Ejemplo n.º 1
0
        public async Task ReturnsModuleRuntimeInfoWhenPodsAreUpdated()
        {
            V1Pod edgeagent1 = BuildPodList()["edgeagent"];

            edgeagent1.Metadata.Name = "edgeagent_123";
            edgeagent1.Status.ContainerStatuses
            .First(c => c.Name == "edgeagent").State.Running.StartedAt = new DateTime(2019, 10, 28);
            V1Pod edgeagent2 = BuildPodList()["edgeagent"];

            edgeagent2.Metadata.Name = "edgeAgent_456";
            edgeagent2.Status.ContainerStatuses
            .First(c => c.Name == "edgeagent").State.Running.StartedAt = new DateTime(2019, 10, 29);
            var client        = new Mock <IKubernetes>(MockBehavior.Strict);
            var moduleManager = new Mock <IModuleManager>(MockBehavior.Strict);
            var runtimeInfo   = new KubernetesRuntimeInfoProvider(Namespace, client.Object, moduleManager.Object);

            runtimeInfo.CreateOrUpdateAddPodInfo(edgeagent1);
            runtimeInfo.CreateOrUpdateAddPodInfo(edgeagent2);
            runtimeInfo.RemovePodInfo(edgeagent1);

            var modules = await runtimeInfo.GetModules(CancellationToken.None);

            var info = modules.Single();

            Assert.NotNull(info);
            Assert.Equal(info.StartTime, Option.Some(new DateTime(2019, 10, 29)));
        }
        public async Task ReturnsRestModulesWhenSomeModulesInfoRemoved()
        {
            Dictionary <string, V1Pod> pods = BuildPodList();
            var client        = new Mock <IKubernetes>(MockBehavior.Strict);
            var moduleManager = new Mock <IModuleManager>(MockBehavior.Strict);
            var runtimeInfo   = new KubernetesRuntimeInfoProvider(Namespace, client.Object, moduleManager.Object);

            runtimeInfo.CreateOrUpdateAddPodInfo("edgeagent", pods["edgeagent"]);
            runtimeInfo.CreateOrUpdateAddPodInfo("edgehub", pods["edgehub"]);
            runtimeInfo.RemovePodInfo("edgeagent");

            var modules = await runtimeInfo.GetModules(CancellationToken.None);

            var info = modules.Single();

            Assert.NotNull(info);
            Assert.Equal("edgeHub", info.Name);
        }