config_test.go 1.2 KB

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