Skip to content

Commit c676422

Browse files
committed
add test for null output plugin
1 parent 9c057a9 commit c676422

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<source>
2+
@type forward
3+
bind 0.0.0.0
4+
port 24224
5+
</source>
6+
<match **>
7+
@id main
8+
@type label_router
9+
<route>
10+
@label @a2170d34e9940ec56d328100e375c43e
11+
<match>
12+
namespaces default,kube-system
13+
</match>
14+
</route>
15+
</match>
16+
<label @a2170d34e9940ec56d328100e375c43e>
17+
<filter **>
18+
@id ClusterFluentdConfig-cluster-fluentd-config::cluster::clusterfilter::fluentd-filter-0
19+
@type record_transformer
20+
enable_ruby true
21+
<record>
22+
kubernetes_ns ${record["kubernetes"]["namespace_name"]}
23+
</record>
24+
</filter>
25+
<match **>
26+
@id ClusterFluentdConfig-cluster-fluentd-config::cluster::clusteroutput::fluentd-output-null-0
27+
@type null
28+
never_flush false
29+
</match>
30+
</label>

apis/fluentd/v1alpha1/tests/helper_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,31 @@ func Test_ClusterCfgOutput2Datadog(t *testing.T) {
381381
}
382382
}
383383

384+
func Test_ClusterCfgOutput2Null(t *testing.T) {
385+
g := NewGomegaWithT(t)
386+
sl := plugins.NewSecretLoader(nil, Fluentd.Namespace, logr.Logger{})
387+
388+
psr := fluentdv1alpha1.NewGlobalPluginResources("main")
389+
psr.CombineGlobalInputsPlugins(sl, Fluentd.Spec.GlobalInputs)
390+
391+
clustercfgRouter, err := psr.BuildCfgRouter(&FluentdClusterFluentdConfig1)
392+
g.Expect(err).NotTo(HaveOccurred())
393+
clusterFilters := []fluentdv1alpha1.ClusterFilter{FluentdClusterFilter1}
394+
clusterOutputs := []fluentdv1alpha1.ClusterOutput{FluentdClusterOutput2Null}
395+
clustercfgResources, _ := psr.PatchAndFilterClusterLevelResources(sl, FluentdClusterFluentdConfig1.GetCfgId(), []fluentdv1alpha1.ClusterInput{}, clusterFilters, clusterOutputs)
396+
err = psr.WithCfgResources(*clustercfgRouter.Label, clustercfgResources)
397+
g.Expect(err).NotTo(HaveOccurred())
398+
399+
i := 0
400+
for i < maxRuntimes {
401+
config, errs := psr.RenderMainConfig(false)
402+
g.Expect(errs).NotTo(HaveOccurred())
403+
g.Expect(strings.TrimSpace(string(getExpectedCfg("./expected/fluentd-cluster-cfg-output-null.cfg")))).To(Equal(config))
404+
405+
i++
406+
}
407+
408+
}
384409
func Test_MixedCfgCopy1(t *testing.T) {
385410
g := NewGomegaWithT(t)
386411
sl := NewSecretLoader(logr.Logger{}, lokiHttpCredentials, lokiTenantName)

apis/fluentd/v1alpha1/tests/tools.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,20 @@ spec:
860860
port: 443
861861
ddSource: kubernetes
862862
ddSourcecategory: kubernetes
863+
`
864+
FluentdClusterOutput2Null fluentdv1alpha1.ClusterOutput
865+
FluentdClusterOutput2NullRaw = `
866+
apiVersion: fluentd.fluent.io/v1alpha1
867+
kind: ClusterOutput
868+
metadata:
869+
name: fluentd-output-null
870+
namespace: fluent
871+
labels:
872+
output.fluentd.fluent.io/enabled: "true"
873+
spec:
874+
outputs:
875+
- nullPlugin:
876+
neverFlush: false
863877
`
864878
FluentdClusterOutputCopy2StdoutAndLoki fluentdv1alpha1.ClusterOutput
865879
FluentdClusterOutputCopy2StdoutAndLokiRaw = `
@@ -1052,6 +1066,7 @@ func init() {
10521066
ParseIntoObject(FluentdClusterOutputCustomRaw, &FluentdClusterOutputCustom)
10531067
ParseIntoObject(FluentdClusterOutput2CloudWatchRaw, &FluentdClusterOutput2CloudWatch)
10541068
ParseIntoObject(FluentdClusterOutput2DatadogRaw, &FluentdClusterOutput2Datadog)
1069+
ParseIntoObject(FluentdClusterOutput2NullRaw, &FluentdClusterOutput2Null)
10551070
ParseIntoObject(FluentdClusterOutputCopy2StdoutAndLokiRaw, &FluentdClusterOutputCopy2StdoutAndLoki)
10561071
ParseIntoObject(FluentdOutputMixedCopy1Raw, &FluentdOutputMixedCopy1)
10571072
ParseIntoObject(FluentdOutputMixedCopy2Raw, &FluentdOutputMixedCopy2)

0 commit comments

Comments
 (0)