@@ -172,8 +172,11 @@ func TestConvertToFragment(t *testing.T) {
172172 },
173173 }
174174
175- state := & mountedFileState {}
176- state .Context = ctx
175+ state := & mountedFileState {
176+ BaseProcessorState : BaseProcessorState {
177+ Context : ctx ,
178+ },
179+ }
177180
178181 result := state .convertToFragement (specC1 )
179182 assert .Equal (t , 2 , len (result ))
@@ -205,3 +208,81 @@ func TestConvertToFragment(t *testing.T) {
205208 assert .Equal (t , "filter" , mod .Name )
206209 assert .Equal (t , "record_modifier" , mod .Type ())
207210}
211+
212+ func TestProcessMountedFile (t * testing.T ) {
213+ c1 := & datasource.MiniContainer {
214+ PodID : "123-id" ,
215+ PodName : "123" ,
216+ Name : "redis-main" ,
217+ Labels : map [string ]string {"app" : "redis" },
218+ HostMounts : []* datasource.Mount {
219+ {
220+ Path : "/var/log" ,
221+ VolumeName : "logs" ,
222+ },
223+ },
224+ }
225+
226+ c2 := & datasource.MiniContainer {
227+ PodID : "abc-id" ,
228+ PodName : "abc" ,
229+ Name : "nginx-main" ,
230+ Labels : map [string ]string {"app" : "nginx" },
231+ HostMounts : []* datasource.Mount {
232+ {
233+ Path : "/var/log" ,
234+ VolumeName : "logs" ,
235+ },
236+ {
237+ Path : "/var" ,
238+ VolumeName : "var" ,
239+ },
240+ },
241+ }
242+
243+ ctx := & ProcessorContext {
244+ Namepsace : "monitoring" ,
245+ KubeletRoot : "/kubelet-root" ,
246+ MiniContainers : []* datasource.MiniContainer {
247+ c1 ,
248+ c2 ,
249+ },
250+ }
251+
252+ state := & mountedFileState {
253+ BaseProcessorState : BaseProcessorState {
254+ Context : ctx ,
255+ },
256+ }
257+
258+ s := `
259+ <source>
260+ @type mounted-file
261+ path /var/log/redis.log
262+ labels app=redis
263+ </source>
264+
265+ <source>
266+ @type mounted-file
267+ path /var/log/nginx.log
268+ labels app=nginx, _container=nginx-main
269+ </source>
270+
271+ <match **>
272+ @type null
273+ </match>
274+ `
275+
276+ input , err := fluentd .ParseString (s )
277+ assert .Nil (t , err , "Must have parsed, instead got error %+v" , err )
278+
279+ prep , err := Prepare (input , ctx , state )
280+ assert .Nil (t , err )
281+ assert .Equal (t , 4 , len (prep ))
282+ assert .Equal (t , "/kubelet-root/pods/123-id/volumes/kubernetes.io~empty-dir/logs/redis.log" , prep [0 ].Param ("path" ))
283+ assert .Equal (t , "/kubelet-root/pods/abc-id/volumes/kubernetes.io~empty-dir/logs/nginx.log" , prep [2 ].Param ("path" ))
284+
285+ main , err := Process (input , ctx , state )
286+ assert .Nil (t , err )
287+ assert .Equal (t , 1 , len (main ))
288+ }
0 commit comments