cscli_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. HubURLTemplate: defaultHubURLTemplate,
  33. },
  34. },
  35. }
  36. for _, tc := range tests {
  37. tc := tc
  38. t.Run(tc.name, func(t *testing.T) {
  39. err := tc.input.loadCSCLI()
  40. cstest.RequireErrorContains(t, err, tc.expectedErr)
  41. if tc.expectedErr != "" {
  42. return
  43. }
  44. assert.Equal(t, tc.expected, tc.input.Cscli)
  45. })
  46. }
  47. }