Skip to content

Commit

Permalink
docs(api/sessionrecording): add example for NewReader
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinspecker committed Dec 20, 2024
1 parent 52473fd commit b73f186
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions api/sessionrecording/session_recording_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package sessionrecording_test

import (
"context"
"fmt"
"os"
"testing"

Expand Down Expand Up @@ -45,3 +46,40 @@ func TestReadCorruptedRecording(t *testing.T) {
// verify that the expected number of events are extracted
require.Len(t, events, 12)
}

// note: testdata/session is not a real session recording, but enough for
// demonstratation purposes
// testdata/session has just enough metadata in the protobuf binary file
// to have the event types populated
func ExampleNewReader() {
// testdata/session includes 4 events
// 1. session.start
// 2. print
// 3. session.end
// 4. session.leave
sessionFile, err := os.Open("testdata/session")
if err != nil {
// handle Open error
return
}
defer sessionFile.Close()

reader := sessionrecording.NewReader(sessionFile)
defer reader.Close()

events, err := reader.ReadAll(context.Background())
if err != nil {
// handle ReadAll error
return
}

// loop through parsed events
for _, event := range events {
fmt.Println(event.GetType())
}

// Output: session.start
// print
// session.end
// session.leave
}
Binary file added api/sessionrecording/testdata/session
Binary file not shown.

0 comments on commit b73f186

Please sign in to comment.