cscli_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. ConfigDir: "./testdata",
  32. DataDir: "./data",
  33. HubDir: "./hub",
  34. HubIndexFile: "./hub/.index.json",
  35. PrometheusUrl: "http://127.0.0.1:6060/metrics",
  36. },
  37. },
  38. }
  39. for _, tc := range tests {
  40. tc := tc
  41. t.Run(tc.name, func(t *testing.T) {
  42. err := tc.input.loadCSCLI()
  43. cstest.RequireErrorContains(t, err, tc.expectedErr)
  44. if tc.expectedErr != "" {
  45. return
  46. }
  47. assert.Equal(t, tc.expected, tc.input.Cscli)
  48. })
  49. }
  50. }