public async Task GetRoutesAsync_DeepClones()
        {
            // Arrange
            var repo   = new InMemoryRoutesRepo();
            var routes = new[]
            {
                new ProxyRoute {
                    RouteId = "route1"
                },
            };

            // Act
            await repo.SetRoutesAsync(routes, CancellationToken.None);

            var result1 = await repo.GetRoutesAsync(CancellationToken.None);

            // Modify first results, should not affect future results
            result1[0].RouteId = "modified";
            result1.Add(new ProxyRoute {
                RouteId = "route2"
            });

            var result2 = await repo.GetRoutesAsync(CancellationToken.None);

            // Assert
            Assert.Single(result2);
            Assert.NotSame(result1, result2);
            Assert.NotSame(routes, result2);
            Assert.Equal("route1", result2[0].RouteId);
        }
        public async Task SetRoutesAsync_DeepClones()
        {
            // Arrange
            var repo   = new InMemoryRoutesRepo();
            var routes = new List <ProxyRoute>
            {
                new ProxyRoute {
                    RouteId = "route1"
                },
            };

            // Act
            await repo.SetRoutesAsync(routes, CancellationToken.None);

            // Modify input, should not affect output
            routes[0].RouteId = "modified";
            routes.Add(new ProxyRoute {
                RouteId = "route2"
            });

            var result = await repo.GetRoutesAsync(CancellationToken.None);

            // Assert
            Assert.Single(result);
            Assert.NotSame(routes, result);
            Assert.Equal("route1", result[0].RouteId);
        }
Exemple #3
0
        private async Task LoadFromIngress(IReverseProxyConfigManager proxyManager)
        {
            var config       = KubernetesClientConfiguration.BuildConfigFromConfigFile();
            var backendsRepo = new InMemoryBackendsRepo();
            var routesRepo   = new InMemoryRoutesRepo()
                               var client = new Kubernetes(config); //inject this?
            var ingress = await client.ListIngressForAllNamespacesWithHttpMessagesAsync(watch : true);

            using (ingress.Watch <Extensionsv1beta1Ingress, Extensionsv1beta1IngressList>((type, item) =>
            {
                Console.WriteLine(type);
                Console.WriteLine(item.Metadata.Name);
            })){
                var ctrlc = new ManualResetEventSlim(false);
                Console.CancelKeyPress += (sender, eventArgs) => ctrlc.Set();
                ctrlc.Wait();
            }

            /*
             * await backendsRepo.SetBackendsAsync(config.Backends, CancellationToken.None);
             * await routesRepo.SetRoutesAsync(config.Routes, CancellationToken.None);
             *
             * var errorReporter = new LoggerConfigErrorReporter(_logger);
             * await _proxyManager.ApplyConfigurationsAsync(errorReporter, CancellationToken.None);
             */
        }
        public async Task SetRoutesAsync_DeepClones()
        {
            // Arrange
            var repo   = new InMemoryRoutesRepo();
            var routes = new List <ProxyRoute>
            {
                new ProxyRoute {
                    RouteId = "route1"
                },
            };

            // Act
            await repo.SetRoutesAsync(routes, CancellationToken.None);

            // Modify input, should not affect output
            routes[0].RouteId = "modified";
            routes.Add(new ProxyRoute {
                RouteId = "route2"
            });

            var result = await repo.GetRoutesAsync(CancellationToken.None);

            // Assert
            result.Should().HaveCount(1);
            result.Should().NotBeSameAs(routes);
            result[0].RouteId.Should().Be("route1");
        }
        public async Task GetRoutesAsync_DeepClones()
        {
            // Arrange
            var repo   = new InMemoryRoutesRepo();
            var routes = new[]
            {
                new ProxyRoute {
                    RouteId = "route1"
                },
            };

            // Act
            await repo.SetRoutesAsync(routes, CancellationToken.None);

            var result1 = await repo.GetRoutesAsync(CancellationToken.None);

            // Modify first results, should not affect future results
            result1[0].RouteId = "modified";
            result1.Add(new ProxyRoute {
                RouteId = "route2"
            });

            var result2 = await repo.GetRoutesAsync(CancellationToken.None);

            // Assert
            result2.Should().HaveCount(1);
            result2.Should().NotBeSameAs(result1);
            result2.Should().NotBeSameAs(routes);
            result2[0].RouteId.Should().Be("route1");
        }
        public async Task GetRoutesAsync_StartsNull()
        {
            // Arrange
            var repo = new InMemoryRoutesRepo();

            // Act
            var result = await repo.GetRoutesAsync(CancellationToken.None);

            // Assert
            Assert.Null(result);
        }
        public void SetRoutesAsync_CompletesSynchronously()
        {
            // Arrange
            var repo = new InMemoryRoutesRepo();

            // Act
            var task = repo.SetRoutesAsync(new ProxyRoute[0], CancellationToken.None);

            // Assert
            Assert.True(task.IsCompleted, "should complete synchronously");
        }
        public void GetRoutesAsync_CompletesSynchronously()
        {
            // Arrange
            var repo = new InMemoryRoutesRepo();

            // Act
            var task = repo.GetRoutesAsync(CancellationToken.None);

            // Assert
            task.IsCompleted.Should().BeTrue("should complete synchronously");
        }
        public async Task SetRoutesAsync_IgnoresCancellation()
        {
            // Arrange
            var repo = new InMemoryRoutesRepo();

            using (var cts = new CancellationTokenSource())
            {
                cts.Cancel();

                // Act & Assert
                await repo.SetRoutesAsync(new ProxyRoute[0], cts.Token);
            }
        }