Skip to content

Commit 4e0cc46

Browse files
authored
pkg/acquisition: refact configuration validation and tests (#4187)
1 parent eb883ee commit 4e0cc46

150 files changed

Lines changed: 1087 additions & 1232 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Under windows, don't mess with line endings at least for yaml test files,
2+
# otherwise the reported line numbers don't match the expected errors.
3+
4+
**/testdata/**/*.yaml text eol=lf
5+
**/testdata/**/*.yml text eol=lf

cmd/crowdsec-cli/clisetup/setup/detect_test.go

Lines changed: 0 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -345,29 +345,6 @@ detect:
345345
datasource: {}`,
346346
want: nil,
347347
wantErr: "invalid acquisition spec for wizard: datasource configuration is empty",
348-
}, {
349-
name: "missing acquisition file name",
350-
config: `
351-
detect:
352-
wizard:
353-
acquisition_spec:
354-
filename: something.yaml
355-
datasource:
356-
labels:
357-
type: something`,
358-
want: nil,
359-
wantErr: "invalid acquisition spec for wizard: source field is required",
360-
}, {
361-
name: "source is unknown",
362-
config: `
363-
detect:
364-
foobar:
365-
acquisition_spec:
366-
filename: wombat.yaml
367-
datasource:
368-
source: wombat`,
369-
want: nil,
370-
wantErr: "invalid acquisition spec for foobar: unknown data source wombat",
371348
}, {
372349
name: "source is misplaced",
373350
config: `
@@ -379,131 +356,6 @@ detect:
379356
source: file`,
380357
want: nil,
381358
wantErr: "yaml: unmarshal errors:\n line 7: field source not found in type setup.AcquisitionSpec",
382-
}, {
383-
name: "source is mismatched",
384-
config: `
385-
detect:
386-
foobar:
387-
acquisition_spec:
388-
filename: journalctl.yaml
389-
datasource:
390-
source: journalctl
391-
filename: /path/to/file.log`,
392-
want: nil,
393-
wantErr: `invalid acquisition spec for foobar: cannot parse: [1:1] unknown field "filename"`,
394-
}, {
395-
name: "source file: required fields",
396-
config: `
397-
detect:
398-
foobar:
399-
acquisition_spec:
400-
filename: file.yaml
401-
datasource:
402-
source: file`,
403-
want: nil,
404-
wantErr: "invalid acquisition spec for foobar: no filename or filenames configuration provided",
405-
}, {
406-
name: "source journalctl: required fields",
407-
config: `
408-
detect:
409-
foobar:
410-
acquisition_spec:
411-
filename: foobar.yaml
412-
datasource:
413-
source: journalctl`,
414-
want: nil,
415-
wantErr: "invalid acquisition spec for foobar: journalctl_filter is required",
416-
}, {
417-
name: "source cloudwatch: required fields",
418-
config: `
419-
detect:
420-
foobar:
421-
acquisition_spec:
422-
filename: cloudwatch.yaml
423-
datasource:
424-
source: cloudwatch`,
425-
want: nil,
426-
wantErr: "invalid acquisition spec for foobar: group_name is mandatory for CloudwatchSource",
427-
}, {
428-
name: "source syslog: all fields are optional",
429-
config: `
430-
detect:
431-
foobar:
432-
acquisition_spec:
433-
filename: syslog.yaml
434-
datasource:
435-
source: syslog`,
436-
want: &Setup{
437-
Plans: []ServicePlan{
438-
{
439-
Name: "foobar",
440-
InstallRecommendation: InstallRecommendation{
441-
AcquisitionSpec: AcquisitionSpec{
442-
Filename: "syslog.yaml",
443-
Datasource: DatasourceConfig{
444-
"source": "syslog",
445-
},
446-
},
447-
},
448-
},
449-
},
450-
},
451-
}, {
452-
name: "source docker: required fields",
453-
config: `
454-
detect:
455-
foobar:
456-
acquisition_spec:
457-
filename: docker.yaml
458-
datasource:
459-
source: docker`,
460-
want: nil,
461-
wantErr: "invalid acquisition spec for foobar: no containers or services configuration provided",
462-
}, {
463-
name: "source kinesis: required fields (enhanced fanout=false)",
464-
config: `
465-
detect:
466-
foobar:
467-
acquisition_spec:
468-
filename: kinesis.yaml
469-
datasource:
470-
source: kinesis`,
471-
want: nil,
472-
wantErr: "invalid acquisition spec for foobar: stream_name is mandatory when use_enhanced_fanout is false",
473-
}, {
474-
name: "source kinesis: required fields (enhanced fanout=true)",
475-
config: `
476-
detect:
477-
foobar:
478-
acquisition_spec:
479-
filename: kinesis.yaml
480-
datasource:
481-
source: kinesis
482-
use_enhanced_fanout: true`,
483-
want: nil,
484-
wantErr: "invalid acquisition spec for foobar: stream_arn is mandatory when use_enhanced_fanout is true",
485-
}, {
486-
name: "source kafka: required fields",
487-
config: `
488-
detect:
489-
foobar:
490-
acquisition_spec:
491-
filename: kafka.yaml
492-
datasource:
493-
source: kafka`,
494-
want: nil,
495-
wantErr: "invalid acquisition spec for foobar: cannot create a kafka reader with an empty list of broker addresses",
496-
}, {
497-
name: "source loki: required fields",
498-
config: `
499-
detect:
500-
foobar:
501-
acquisition_spec:
502-
filename: loki.yaml
503-
datasource:
504-
source: loki`,
505-
want: nil,
506-
wantErr: "invalid acquisition spec for foobar: loki query is mandatory",
507359
},
508360
}
509361

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ require (
7171
github.com/prometheus/common v0.66.1
7272
github.com/r3labs/diff/v2 v2.15.1
7373
github.com/sanity-io/litter v1.5.8
74+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2
7475
github.com/segmentio/kafka-go v0.4.48
7576
github.com/shirou/gopsutil/v4 v4.25.8
7677
github.com/sirupsen/logrus v1.9.3

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
148148
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
149149
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
150150
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
151+
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
152+
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
151153
github.com/docker/go-connections v0.6.0 h1:LlMG9azAe1TqfR7sO+NJttz1gy6KO7VJBh+pMmjSD94=
152154
github.com/docker/go-connections v0.6.0/go.mod h1:AahvXYshr6JgfUJGdDCs2b5EZG/vmaMAntpSFH5BFKE=
153155
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
@@ -508,6 +510,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf
508510
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
509511
github.com/sanity-io/litter v1.5.8 h1:uM/2lKrWdGbRXDrIq08Lh9XtVYoeGtcQxk9rtQ7+rYg=
510512
github.com/sanity-io/litter v1.5.8/go.mod h1:9gzJgR2i4ZpjZHsKvUXIRQVk7P+yM3e+jAF7bU2UI5U=
513+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 h1:KRzFb2m7YtdldCEkzs6KqmJw4nqEVZGK7IN2kJkjTuQ=
514+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
511515
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
512516
github.com/segmentio/kafka-go v0.4.48 h1:9jyu9CWK4W5W+SroCe8EffbrRZVqAOkuaLd/ApID4Vs=
513517
github.com/segmentio/kafka-go v0.4.48/go.mod h1:HjF6XbOKh0Pjlkr5GVZxt6CsjjwnmhVOfURM5KMd8qg=

0 commit comments

Comments
 (0)