public async void HandleHealthRequestAsync_ReturnsExpected()
        {
            var opts        = new HealthEndpointOptions();
            var mgmtOptions = new CloudFoundryManagementOptions();

            mgmtOptions.EndpointOptions.Add(opts);
            var contribs = new List <IHealthContributor>()
            {
                new DiskSpaceContributor()
            };
            var ep     = new TestHealthEndpoint(opts, new DefaultHealthAggregator(), contribs);
            var middle = new HealthEndpointMiddleware(null, new List <IManagementOptions> {
                mgmtOptions
            });

            middle.Endpoint = ep;

            var context = CreateRequest("GET", "/health");
            await middle.HandleHealthRequestAsync(context);

            context.Response.Body.Seek(0, SeekOrigin.Begin);
            StreamReader rdr  = new StreamReader(context.Response.Body);
            string       json = await rdr.ReadToEndAsync();

            Assert.Equal("{\"status\":\"UNKNOWN\"}", json);
        }
        public void HealthEndpointMiddleware_PathAndVerbMatching_ReturnsExpected()
        {
            var opts = new HealthEndpointOptions();
            var contribs = new List<IHealthContributor>() { new DiskSpaceContributor() };
            var ep = new HealthEndpoint(opts, new DefaultHealthAggregator(), contribs);
            var actMOptions = new ActuatorManagementOptions();
            actMOptions.EndpointOptions.Add(opts);
            var middle = new HealthEndpointMiddleware(null, ep, new List<IManagementOptions> { actMOptions });

            Assert.True(middle.RequestVerbAndPathMatch("GET", "/actuator/health"));
            Assert.False(middle.RequestVerbAndPathMatch("PUT", "/actuator/health"));
            Assert.False(middle.RequestVerbAndPathMatch("GET", "/actuator/badpath"));
        }
        public void HealthEndpointMiddleware_PathAndVerbMatching_ReturnsExpected()
        {
            var opts     = new HealthOptions();
            var contribs = new List <IHealthContributor>()
            {
                new DiskSpaceContributor()
            };
            var ep     = new HealthEndpoint(opts, new DefaultHealthAggregator(), contribs);
            var middle = new HealthEndpointMiddleware(null);

            middle.Endpoint = ep;

            Assert.True(middle.RequestVerbAndPathMatch("GET", "/health"));
            Assert.False(middle.RequestVerbAndPathMatch("PUT", "/health"));
            Assert.False(middle.RequestVerbAndPathMatch("GET", "/badpath"));
        }
        public void IsHealthRequest_ReturnsExpected()
        {
            var opts     = new HealthOptions();
            var contribs = new List <IHealthContributor>()
            {
                new DiskSpaceContributor()
            };
            var ep     = new HealthEndpoint(opts, new DefaultHealthAggregator(), contribs);
            var middle = new HealthEndpointMiddleware(null, ep);

            var context = CreateRequest("GET", "/health");

            Assert.True(middle.IsHealthRequest(context));

            var context2 = CreateRequest("PUT", "/health");

            Assert.False(middle.IsHealthRequest(context2));

            var context3 = CreateRequest("GET", "/badpath");

            Assert.False(middle.IsHealthRequest(context3));
        }