http_server_test.go 746 B

123456789101112131415161718192021222324252627282930
  1. package api
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/setting"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestHTTPServer(t *testing.T) {
  8. Convey("Given a HTTPServer", t, func() {
  9. ts := &HTTPServer{
  10. Cfg: setting.NewCfg(),
  11. }
  12. Convey("Given that basic auth on the metrics endpoint is enabled", func() {
  13. ts.Cfg.MetricsEndpointBasicAuthUsername = "foo"
  14. ts.Cfg.MetricsEndpointBasicAuthPassword = "bar"
  15. So(ts.metricsEndpointBasicAuthEnabled(), ShouldBeTrue)
  16. })
  17. Convey("Given that basic auth on the metrics endpoint is disabled", func() {
  18. ts.Cfg.MetricsEndpointBasicAuthUsername = ""
  19. ts.Cfg.MetricsEndpointBasicAuthPassword = ""
  20. So(ts.metricsEndpointBasicAuthEnabled(), ShouldBeFalse)
  21. })
  22. })
  23. }