github.com/crowdsecurity/crowdsec@v1.6.1/pkg/csconfig/config_test.go (about)

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