cscli_test.go 1014 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package csconfig
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/crowdsecurity/go-cs-lib/cstest"
  6. )
  7. func TestLoadCSCLI(t *testing.T) {
  8. tests := []struct {
  9. name string
  10. input *Config
  11. expected *CscliCfg
  12. expectedErr string
  13. }{
  14. {
  15. name: "basic valid configuration",
  16. input: &Config{
  17. ConfigPaths: &ConfigurationPaths{
  18. ConfigDir: "./testdata",
  19. DataDir: "./data",
  20. HubDir: "./hub",
  21. HubIndexFile: "./hub/.index.json",
  22. },
  23. Prometheus: &PrometheusCfg{
  24. Enabled: true,
  25. Level: "full",
  26. ListenAddr: "127.0.0.1",
  27. ListenPort: 6060,
  28. },
  29. },
  30. expected: &CscliCfg{
  31. PrometheusUrl: "http://127.0.0.1:6060/metrics",
  32. },
  33. },
  34. }
  35. for _, tc := range tests {
  36. tc := tc
  37. t.Run(tc.name, func(t *testing.T) {
  38. err := tc.input.loadCSCLI()
  39. cstest.RequireErrorContains(t, err, tc.expectedErr)
  40. if tc.expectedErr != "" {
  41. return
  42. }
  43. assert.Equal(t, tc.expected, tc.input.Cscli)
  44. })
  45. }
  46. }