44 "context"
55 "errors"
66 "os"
7+ "reflect"
78 "runtime"
89 "testing"
910 "time"
@@ -27,13 +28,15 @@ func TestNew_WithEventStoreAsRoot_KmsgSyncer_WithMockey(t *testing.T) {
2728
2829 bucket := & memoryEventBucket {}
2930 var match kmsg.MatchFunc
31+ var syncerOpts []kmsg.OpOption
3032 mockey .Mock (kmsg .NewSyncer ).To (func (
3133 _ context.Context ,
3234 matchFunc kmsg.MatchFunc ,
3335 eventBucket eventstore.Bucket ,
34- _ ... kmsg.OpOption ,
36+ opts ... kmsg.OpOption ,
3537 ) (* kmsg.Syncer , error ) {
3638 match = matchFunc
39+ syncerOpts = opts
3740 assert .Same (t , bucket , eventBucket )
3841 return & kmsg.Syncer {}, nil
3942 }).Build ()
@@ -48,6 +51,8 @@ func TestNew_WithEventStoreAsRoot_KmsgSyncer_WithMockey(t *testing.T) {
4851 require .NotNil (t , c .kmsgSyncer )
4952 assert .Nil (t , c .readAllKmsg , "daemon components should rely on the kmsg syncer" )
5053 require .NotNil (t , match )
54+ require .Len (t , syncerOpts , 1 )
55+ assert .Equal (t , int (defaultKmsgEventDedupWindow .Seconds ()), getKmsgCacheKeyTruncateSeconds (t , syncerOpts [0 ]))
5156
5257 name , message := match ("NVRM: knvlinkDiscoverPostRxDetLinks_GH100: Getting peer0's postRxDetLinkMask failed!" )
5358 assert .Equal (t , EventNamePostRxDetectFailure , name )
@@ -63,6 +68,17 @@ func TestNew_WithEventStoreAsRoot_KmsgSyncer_WithMockey(t *testing.T) {
6368 })
6469}
6570
71+ func getKmsgCacheKeyTruncateSeconds (t * testing.T , opt kmsg.OpOption ) int {
72+ t .Helper ()
73+ op := & kmsg.Op {}
74+ opt (op )
75+
76+ v := reflect .ValueOf (op ).Elem ().FieldByName ("cacheKeyTruncateSeconds" )
77+ require .True (t , v .IsValid (), "cacheKeyTruncateSeconds field must exist" )
78+ require .Equal (t , reflect .Int , v .Kind (), "cacheKeyTruncateSeconds must be int" )
79+ return int (v .Int ())
80+ }
81+
6682func TestNew_WithEventStoreAsRoot_KmsgSyncerError_WithMockey (t * testing.T ) {
6783 mockey .PatchConvey ("New cleans up when the kmsg syncer cannot be created" , t , func () {
6884 mockey .Mock (os .Geteuid ).Return (0 ).Build ()
0 commit comments