@@ -554,3 +554,145 @@ func TestSessionDeleteActives(t *testing.T) {
554554 })
555555 }
556556}
557+
558+ func TestSessionListEvents (t * testing.T ) {
559+ type Expected struct {
560+ events []models.SessionEvent
561+ count int
562+ err error
563+ }
564+
565+ cases := []struct {
566+ description string
567+ uid string
568+ paginator query.Paginator
569+ sorter query.Sorter
570+ filters query.Filters
571+ fixtures []string
572+ expected Expected
573+ }{
574+ {
575+ description : "succeeds when sessions are not found" ,
576+ uid : "nonexistent" ,
577+ paginator : query.Paginator {Page : - 1 , PerPage : - 1 },
578+ sorter : query.Sorter {By : "timestamp" , Order : query .OrderAsc },
579+ filters : query.Filters {},
580+ fixtures : []string {
581+ fixtureNamespaces ,
582+ fixtureDevices ,
583+ fixtureSessions ,
584+ fixtureActiveSessions ,
585+ fixtureSessionsEvents ,
586+ },
587+ expected : Expected {
588+ events : []models.SessionEvent {},
589+ count : 0 ,
590+ err : nil ,
591+ },
592+ },
593+ {
594+ description : "succeeds when sessions are found" ,
595+ uid : "a3b0431f5df6a7827945d2e34872a5c781452bc36de42f8b1297fd9ecb012f68" ,
596+ paginator : query.Paginator {Page : - 1 , PerPage : - 1 },
597+ sorter : query.Sorter {By : "timestamp" , Order : query .OrderAsc },
598+ filters : query.Filters {},
599+ fixtures : []string {
600+ fixtureNamespaces ,
601+ fixtureDevices ,
602+ fixtureSessions ,
603+ fixtureActiveSessions ,
604+ fixtureSessionsEvents ,
605+ },
606+ expected : Expected {
607+ events : []models.SessionEvent {
608+ {
609+ Session : "a3b0431f5df6a7827945d2e34872a5c781452bc36de42f8b1297fd9ecb012f68" ,
610+ Type : "pty-req" ,
611+ Timestamp : time .Date (2023 , 1 , 2 , 12 , 0 , 0 , 0 , time .UTC ),
612+ Data : models.SSHPty {
613+ Term : "screen-256color" ,
614+ Columns : 211 ,
615+ Rows : 47 ,
616+ Width : 1899 ,
617+ Height : 940 ,
618+ Modelist : []byte {},
619+ },
620+ Seat : 0 ,
621+ },
622+ {
623+ Session : "a3b0431f5df6a7827945d2e34872a5c781452bc36de42f8b1297fd9ecb012f68" ,
624+ Type : "shell" ,
625+ Timestamp : time .Date (2023 , 1 , 2 , 12 , 1 , 0 , 0 , time .UTC ),
626+ Data : "" ,
627+ Seat : 0 ,
628+ },
629+ {
630+ Session : "a3b0431f5df6a7827945d2e34872a5c781452bc36de42f8b1297fd9ecb012f68" ,
631+ Type : "exit-status" ,
632+ Timestamp : time .Date (2023 , 1 , 2 , 12 , 2 , 0 , 0 , time .UTC ),
633+ Data : "AAAAAA==" ,
634+ Seat : 0 ,
635+ },
636+ },
637+ count : 3 ,
638+ err : nil ,
639+ },
640+ },
641+ {
642+ description : "succeeds when sessions are found by page are limited" ,
643+ uid : "a3b0431f5df6a7827945d2e34872a5c781452bc36de42f8b1297fd9ecb012f68" ,
644+ paginator : query.Paginator {Page : 1 , PerPage : 2 },
645+ sorter : query.Sorter {By : "timestamp" , Order : query .OrderAsc },
646+ filters : query.Filters {},
647+ fixtures : []string {
648+ fixtureNamespaces ,
649+ fixtureDevices ,
650+ fixtureSessions ,
651+ fixtureActiveSessions ,
652+ fixtureSessionsEvents ,
653+ },
654+ expected : Expected {
655+ events : []models.SessionEvent {
656+ {
657+ Session : "a3b0431f5df6a7827945d2e34872a5c781452bc36de42f8b1297fd9ecb012f68" ,
658+ Type : "pty-req" ,
659+ Timestamp : time .Date (2023 , 1 , 2 , 12 , 0 , 0 , 0 , time .UTC ),
660+ Data : models.SSHPty {
661+ Term : "screen-256color" ,
662+ Columns : 211 ,
663+ Rows : 47 ,
664+ Width : 1899 ,
665+ Height : 940 ,
666+ Modelist : []byte {},
667+ },
668+ Seat : 0 ,
669+ },
670+ {
671+ Session : "a3b0431f5df6a7827945d2e34872a5c781452bc36de42f8b1297fd9ecb012f68" ,
672+ Type : "shell" ,
673+ Timestamp : time .Date (2023 , 1 , 2 , 12 , 1 , 0 , 0 , time .UTC ),
674+ Data : "" ,
675+ Seat : 0 ,
676+ },
677+ },
678+ count : 3 ,
679+ err : nil ,
680+ },
681+ },
682+ }
683+
684+ for _ , tc := range cases {
685+ t .Run (tc .description , func (t * testing.T ) {
686+ ctx := context .Background ()
687+
688+ assert .NoError (t , srv .Apply (tc .fixtures ... ))
689+ t .Cleanup (func () {
690+ assert .NoError (t , srv .Reset ())
691+ })
692+
693+ events , count , err := s .SessionListEvents (ctx , models .UID (tc .uid ), tc .paginator , tc .filters , tc .sorter )
694+
695+ assert .Equal (t , tc .expected , Expected {events : events , count : count , err : err })
696+ })
697+ }
698+ }
0 commit comments