moar tests
This commit is contained in:
parent
547befb7fd
commit
583ac05cec
6 changed files with 61 additions and 3 deletions
|
@ -195,10 +195,14 @@ func LoadAcquisitionFromFile(config *csconfig.CrowdsecServiceCfg) ([]DataSource,
|
|||
if err := yaml.Unmarshal(inBytes, &sub); err != nil {
|
||||
return nil, errors.Wrapf(err, "configuration isn't valid config in %s : %s", acquisFile, string(inBytes))
|
||||
}
|
||||
sub.ConfigFile = acquisFile
|
||||
//it's an empty item, skip it
|
||||
if len(sub.Labels) == 0 {
|
||||
log.Debugf("skipping empty item in %s", acquisFile)
|
||||
continue
|
||||
if sub.Type == "" {
|
||||
log.Debugf("skipping empty item in %s", acquisFile)
|
||||
continue
|
||||
}
|
||||
return nil, fmt.Errorf("missing labels in %s", acquisFile)
|
||||
}
|
||||
//for backward compat ('type' was not mandatory, detect it)
|
||||
if guessType := detectBackwardCompatAcquis(inBytes); guessType != "" {
|
||||
|
@ -213,7 +217,7 @@ func LoadAcquisitionFromFile(config *csconfig.CrowdsecServiceCfg) ([]DataSource,
|
|||
}
|
||||
src, err := DataSourceConfigure(inBytes, sub)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "while configuring datasource from %s", acquisFile)
|
||||
return nil, errors.Wrapf(err, "while configuring datasource of type %s from %s", sub.Type, sub.ConfigFile)
|
||||
}
|
||||
sources = append(sources, *src)
|
||||
}
|
||||
|
|
|
@ -243,6 +243,34 @@ func TestLoadAcquisitionFromFile(t *testing.T) {
|
|||
},
|
||||
ExpectedLen: 2,
|
||||
},
|
||||
{
|
||||
TestName: "missing_labels",
|
||||
Config: csconfig.CrowdsecServiceCfg{
|
||||
AcquisitionFiles: []string{"test_files/missing_labels.yaml"},
|
||||
},
|
||||
ExpectedError: "missing labels in test_files/missing_labels.yaml",
|
||||
},
|
||||
{
|
||||
TestName: "backward_compat",
|
||||
Config: csconfig.CrowdsecServiceCfg{
|
||||
AcquisitionFiles: []string{"test_files/backward_compat.yaml"},
|
||||
},
|
||||
ExpectedLen: 2,
|
||||
},
|
||||
{
|
||||
TestName: "bad_type",
|
||||
Config: csconfig.CrowdsecServiceCfg{
|
||||
AcquisitionFiles: []string{"test_files/bad_source.yaml"},
|
||||
},
|
||||
ExpectedError: "unknown data source does_not_exist in test_files/bad_source.yaml",
|
||||
},
|
||||
{
|
||||
TestName: "invalid_filetype_config",
|
||||
Config: csconfig.CrowdsecServiceCfg{
|
||||
AcquisitionFiles: []string{"test_files/bad_filetype.yaml"},
|
||||
},
|
||||
ExpectedError: "while configuring datasource of type file from test_files/bad_filetype.yaml",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
dss, err := LoadAcquisitionFromFile(&test.Config)
|
||||
|
|
15
pkg/acquisition/test_files/backward_compat.yaml
Normal file
15
pkg/acquisition/test_files/backward_compat.yaml
Normal file
|
@ -0,0 +1,15 @@
|
|||
filename: /tmp/test.log
|
||||
labels:
|
||||
type: syslog
|
||||
---
|
||||
filenames:
|
||||
- /tmp/test*.log
|
||||
labels:
|
||||
type: syslog
|
||||
---
|
||||
# to be uncommented when we reimplement back journalctl
|
||||
# journalctl_filter:
|
||||
# - "_SYSTEMD_UNIT=ssh.service"
|
||||
# labels:
|
||||
# type: syslog
|
||||
---
|
5
pkg/acquisition/test_files/bad_filetype.yaml
Normal file
5
pkg/acquisition/test_files/bad_filetype.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
type: file
|
||||
filenames: /tmp/tltlt.log #it should be an array
|
||||
labels:
|
||||
type: syslog
|
||||
|
4
pkg/acquisition/test_files/bad_source.yaml
Normal file
4
pkg/acquisition/test_files/bad_source.yaml
Normal file
|
@ -0,0 +1,4 @@
|
|||
type: does_not_exist
|
||||
labels:
|
||||
type: syslog
|
||||
foobar: toto
|
2
pkg/acquisition/test_files/missing_labels.yaml
Normal file
2
pkg/acquisition/test_files/missing_labels.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
type: file
|
||||
filename: /tmp/test.log
|
Loading…
Reference in a new issue