mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 20:36:12 +02:00
Refactor hub management and cscli commands (#2545)
This commit is contained in:
parent
32e9eb4be4
commit
ffcab0b2bc
124 changed files with 6836 additions and 4414 deletions
|
@ -1,32 +1,18 @@
|
|||
package csconfig
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
)
|
||||
|
||||
func TestLoadHub(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 *Hub
|
||||
expected *LocalHubCfg
|
||||
expectedErr string
|
||||
}{
|
||||
{
|
||||
|
@ -39,35 +25,19 @@ func TestLoadHub(t *testing.T) {
|
|||
HubIndexFile: "./hub/.index.json",
|
||||
},
|
||||
},
|
||||
expected: &Hub{
|
||||
HubDir: hubFullPath,
|
||||
HubIndexFile: hubIndexFileFullPath,
|
||||
InstallDir: configDirFullPath,
|
||||
InstallDataDir: dataFullPath,
|
||||
expected: &LocalHubCfg{
|
||||
HubDir: "./hub",
|
||||
HubIndexFile: "./hub/.index.json",
|
||||
InstallDir: "./testdata",
|
||||
InstallDataDir: "./data",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no data dir",
|
||||
input: &Config{
|
||||
ConfigPaths: &ConfigurationPaths{
|
||||
ConfigDir: "./testdata",
|
||||
HubDir: "./hub",
|
||||
HubIndexFile: "./hub/.index.json",
|
||||
},
|
||||
},
|
||||
expectedErr: "please provide a data directory with the 'data_dir' directive in the 'config_paths' section",
|
||||
},
|
||||
{
|
||||
name: "no configuration path",
|
||||
input: &Config{},
|
||||
expectedErr: "no configuration paths provided",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
err := tc.input.LoadHub()
|
||||
err := tc.input.loadHub()
|
||||
cstest.RequireErrorContains(t, err, tc.expectedErr)
|
||||
if tc.expectedErr != "" {
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue