config_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package csconfig
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. "github.com/crowdsecurity/crowdsec/pkg/cstest"
  7. )
  8. func TestNormalLoad(t *testing.T) {
  9. _, err := NewConfig("./tests/config.yaml", false, false, false)
  10. require.NoError(t, err)
  11. _, err = NewConfig("./tests/xxx.yaml", false, false, false)
  12. assert.EqualError(t, err, "while reading yaml file: open ./tests/xxx.yaml: "+cstest.FileNotFoundMessage)
  13. _, err = NewConfig("./tests/simulation.yaml", false, false, false)
  14. assert.EqualError(t, err, "./tests/simulation.yaml: yaml: unmarshal errors:\n line 1: field simulation not found in type csconfig.Config")
  15. }
  16. func TestNewCrowdSecConfig(t *testing.T) {
  17. tests := []struct {
  18. name string
  19. expectedResult *Config
  20. }{
  21. {
  22. name: "new configuration: basic",
  23. expectedResult: &Config{},
  24. },
  25. }
  26. for _, tc := range tests {
  27. tc := tc
  28. t.Run(tc.name, func(t *testing.T) {
  29. result := &Config{}
  30. assert.Equal(t, tc.expectedResult, result)
  31. })
  32. }
  33. }
  34. func TestDefaultConfig(t *testing.T) {
  35. x := NewDefaultConfig()
  36. err := x.Dump()
  37. require.NoError(t, err)
  38. }