-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1143 from MarkusFreitag/bugfix-namespaced-filters
Bugfix namespaced filters
- Loading branch information
Showing
7 changed files
with
188 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package v1alpha2 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins" | ||
"github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins/filter" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func ptr[T any](v T) *T { return &v } | ||
|
||
func TestFilterList_Load(t *testing.T) { | ||
testcases := []struct { | ||
name string | ||
input Filter | ||
expected string | ||
}{ | ||
{ | ||
name: "a single filteritem", | ||
input: Filter{ | ||
Spec: FilterSpec{ | ||
FilterItems: []FilterItem{ | ||
FilterItem{ | ||
Parser: &filter.Parser{ | ||
KeyName: "log", | ||
Parser: "first-parser", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: `[Filter] | ||
Name parser | ||
Key_Name log | ||
Parser first-parser-d41d8cd98f00b204e9800998ecf8427e | ||
`, | ||
}, | ||
{ | ||
name: "a single filteritem, with multiple plugins", | ||
input: Filter{ | ||
Spec: FilterSpec{ | ||
FilterItems: []FilterItem{ | ||
FilterItem{ | ||
Kubernetes: &filter.Kubernetes{ | ||
KubeTagPrefix: "custom-tag", | ||
}, | ||
Parser: &filter.Parser{ | ||
KeyName: "log", | ||
Parser: "first-parser", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: `[Filter] | ||
Name kubernetes | ||
Kube_Tag_Prefix d41d8cd98f00b204e9800998ecf8427e.custom-tag | ||
[Filter] | ||
Name parser | ||
Key_Name log | ||
Parser first-parser-d41d8cd98f00b204e9800998ecf8427e | ||
`, | ||
}, | ||
{ | ||
name: "multiple filteritems", | ||
input: Filter{ | ||
Spec: FilterSpec{ | ||
FilterItems: []FilterItem{ | ||
FilterItem{ | ||
Kubernetes: &filter.Kubernetes{ | ||
KubeTagPrefix: "custom-tag", | ||
}, | ||
Parser: &filter.Parser{ | ||
KeyName: "log", | ||
Parser: "first-parser", | ||
}, | ||
}, | ||
FilterItem{ | ||
Parser: &filter.Parser{ | ||
KeyName: "msg", | ||
Parser: "second-parser", | ||
ReserveData: ptr(true), | ||
}, | ||
}, | ||
FilterItem{ | ||
Parser: &filter.Parser{ | ||
KeyName: "msg", | ||
Parser: "third-parser", | ||
ReserveData: ptr(true), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: `[Filter] | ||
Name kubernetes | ||
Kube_Tag_Prefix d41d8cd98f00b204e9800998ecf8427e.custom-tag | ||
[Filter] | ||
Name parser | ||
Key_Name log | ||
Parser first-parser-d41d8cd98f00b204e9800998ecf8427e | ||
[Filter] | ||
Name parser | ||
Key_Name msg | ||
Parser second-parser-d41d8cd98f00b204e9800998ecf8427e | ||
Reserve_Data true | ||
[Filter] | ||
Name parser | ||
Key_Name msg | ||
Parser third-parser-d41d8cd98f00b204e9800998ecf8427e | ||
Reserve_Data true | ||
`, | ||
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
g := NewGomegaWithT(t) | ||
|
||
sl := plugins.NewSecretLoader(nil, "testnamespace") | ||
|
||
fl := FilterList{ | ||
Items: make([]Filter, 1), | ||
} | ||
fl.Items[0] = tc.input | ||
|
||
renderedFilterList, err := fl.Load(sl) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
g.Expect(renderedFilterList).To(Equal(tc.expected)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters