123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package csconfig
- import (
- "path/filepath"
- "testing"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
- "github.com/crowdsecurity/go-cs-lib/cstest"
- )
- func TestLoadCSCLI(t *testing.T) {
- hubFullPath, err := filepath.Abs("./hub")
- require.NoError(t, err)
- dataFullPath, err := filepath.Abs("./data")
- require.NoError(t, err)
- configDirFullPath, err := filepath.Abs("./testdata")
- require.NoError(t, err)
- hubIndexFileFullPath, err := filepath.Abs("./hub/.index.json")
- require.NoError(t, err)
- tests := []struct {
- name string
- input *Config
- expected *CscliCfg
- expectedErr string
- }{
- {
- name: "basic valid configuration",
- input: &Config{
- ConfigPaths: &ConfigurationPaths{
- ConfigDir: "./testdata",
- DataDir: "./data",
- HubDir: "./hub",
- HubIndexFile: "./hub/.index.json",
- },
- },
- expected: &CscliCfg{
- ConfigDir: configDirFullPath,
- DataDir: dataFullPath,
- HubDir: hubFullPath,
- HubIndexFile: hubIndexFileFullPath,
- },
- },
- {
- name: "no configuration path",
- input: &Config{},
- expected: &CscliCfg{},
- expectedErr: "no configuration paths provided",
- },
- }
- for _, tc := range tests {
- tc := tc
- t.Run(tc.name, func(t *testing.T) {
- err := tc.input.LoadCSCLI()
- cstest.RequireErrorContains(t, err, tc.expectedErr)
- if tc.expectedErr != "" {
- return
- }
- assert.Equal(t, tc.expected, tc.input.Cscli)
- })
- }
- }
|