|
| 1 | +package output |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins" |
| 7 | + "github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params" |
| 8 | + "github.com/fluent/fluent-operator/v3/pkg/utils" |
| 9 | + . "github.com/onsi/gomega" |
| 10 | +) |
| 11 | + |
| 12 | +func TestOutput_Syslog_Params(t *testing.T) { |
| 13 | + g := NewGomegaWithT(t) |
| 14 | + |
| 15 | + sl := plugins.NewSecretLoader(nil, "test-namespace") |
| 16 | + |
| 17 | + // Initialize Syslog struct based on your provided types |
| 18 | + syslog := Syslog{ |
| 19 | + Host: "127.0.0.1", |
| 20 | + Port: utils.ToPtr[int32](514), |
| 21 | + Mode: "tcp", |
| 22 | + SyslogFormat: "rfc5424", |
| 23 | + SyslogMaxSize: utils.ToPtr[int32](2048), |
| 24 | + SyslogSeverityKey: "severity", |
| 25 | + SyslogFacilityKey: "facility", |
| 26 | + SyslogHostnameKey: "hostname", |
| 27 | + SyslogAppnameKey: "appname", |
| 28 | + SyslogProcessIDKey: "pid", |
| 29 | + SyslogMessageIDKey: "msgid", |
| 30 | + SyslogSDKey: "structured_data", |
| 31 | + SyslogMessageKey: "message", |
| 32 | + TotalLimitSize: "1G", |
| 33 | + workers: utils.ToPtr[int32](2), |
| 34 | + } |
| 35 | + |
| 36 | + // Define the expected Key-Value pairs based on your Params() logic |
| 37 | + expected := params.NewKVs() |
| 38 | + expected.Insert("Host", "127.0.0.1") |
| 39 | + expected.Insert("port", "514") |
| 40 | + expected.Insert("mode", "tcp") |
| 41 | + expected.Insert("syslog_hostname_key", "hostname") |
| 42 | + expected.Insert("syslog_appname_key", "appname") |
| 43 | + expected.Insert("syslog_message_key", "message") |
| 44 | + expected.Insert("syslog_format", "rfc5424") |
| 45 | + expected.Insert("syslog_severity_key", "severity") |
| 46 | + expected.Insert("syslog_facility_key", "facility") |
| 47 | + expected.Insert("syslog_procid_key", "pid") // Note: matches your implementation |
| 48 | + expected.Insert("syslog_msgid_key", "msgid") |
| 49 | + expected.Insert("syslog_sd_key", "structured_data") // Note: matches your implementation |
| 50 | + expected.Insert("storage.total_limit_size", "1G") |
| 51 | + expected.Insert("syslog_maxsize", "2048") |
| 52 | + expected.Insert("workers", "2") |
| 53 | + |
| 54 | + // Execute the translation |
| 55 | + kvs, err := syslog.Params(sl) |
| 56 | + |
| 57 | + // Assertions |
| 58 | + g.Expect(err).NotTo(HaveOccurred()) |
| 59 | + g.Expect(kvs).To(Equal(expected)) |
| 60 | +} |
0 commit comments