prometheus_test.go 803 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package csconfig
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/require"
  5. "github.com/crowdsecurity/go-cs-lib/cstest"
  6. )
  7. func TestLoadPrometheus(t *testing.T) {
  8. tests := []struct {
  9. name string
  10. input *Config
  11. expectedURL string
  12. expectedErr string
  13. }{
  14. {
  15. name: "basic valid configuration",
  16. input: &Config{
  17. Prometheus: &PrometheusCfg{
  18. Enabled: true,
  19. Level: "full",
  20. ListenAddr: "127.0.0.1",
  21. ListenPort: 6060,
  22. },
  23. Cscli: &CscliCfg{},
  24. },
  25. expectedURL: "http://127.0.0.1:6060",
  26. },
  27. }
  28. for _, tc := range tests {
  29. tc := tc
  30. t.Run(tc.name, func(t *testing.T) {
  31. err := tc.input.LoadPrometheus()
  32. cstest.RequireErrorContains(t, err, tc.expectedErr)
  33. require.Equal(t, tc.expectedURL, tc.input.Cscli.PrometheusUrl)
  34. })
  35. }
  36. }