2021-03-24 17:16:17 +00:00
|
|
|
package csconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-10-09 09:10:51 +00:00
|
|
|
|
|
|
|
"github.com/crowdsecurity/go-cs-lib/cstest"
|
2021-03-24 17:16:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoadHub(t *testing.T) {
|
|
|
|
tests := []struct {
|
2023-10-09 09:10:51 +00:00
|
|
|
name string
|
|
|
|
input *Config
|
2023-11-24 14:57:32 +00:00
|
|
|
expected *LocalHubCfg
|
2023-10-09 09:10:51 +00:00
|
|
|
expectedErr string
|
2021-03-24 17:16:17 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "basic valid configuration",
|
2023-10-09 09:10:51 +00:00
|
|
|
input: &Config{
|
2021-03-24 17:16:17 +00:00
|
|
|
ConfigPaths: &ConfigurationPaths{
|
2023-10-09 09:10:51 +00:00
|
|
|
ConfigDir: "./testdata",
|
2021-03-24 17:16:17 +00:00
|
|
|
DataDir: "./data",
|
|
|
|
HubDir: "./hub",
|
|
|
|
HubIndexFile: "./hub/.index.json",
|
|
|
|
},
|
|
|
|
},
|
2023-11-24 14:57:32 +00:00
|
|
|
expected: &LocalHubCfg{
|
|
|
|
HubDir: "./hub",
|
|
|
|
HubIndexFile: "./hub/.index.json",
|
|
|
|
InstallDir: "./testdata",
|
|
|
|
InstallDataDir: "./data",
|
2021-03-24 17:16:17 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-10-09 09:10:51 +00:00
|
|
|
for _, tc := range tests {
|
|
|
|
tc := tc
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2023-11-24 14:57:32 +00:00
|
|
|
err := tc.input.loadHub()
|
2023-10-09 09:10:51 +00:00
|
|
|
cstest.RequireErrorContains(t, err, tc.expectedErr)
|
|
|
|
if tc.expectedErr != "" {
|
|
|
|
return
|
2021-03-24 17:16:17 +00:00
|
|
|
}
|
2023-10-09 09:10:51 +00:00
|
|
|
|
|
|
|
assert.Equal(t, tc.expected, tc.input.Hub)
|
|
|
|
})
|
2021-03-24 17:16:17 +00:00
|
|
|
}
|
|
|
|
}
|