From b73f186cadeb373eb915c5b1a23d2bf223fec1bd Mon Sep 17 00:00:00 2001 From: Dustin Specker Date: Fri, 20 Dec 2024 13:39:45 -0600 Subject: [PATCH] docs(api/sessionrecording): add example for NewReader --- .../session_recording_test.go | 38 ++++++++++++++++++ api/sessionrecording/testdata/session | Bin 0 -> 392 bytes 2 files changed, 38 insertions(+) create mode 100644 api/sessionrecording/testdata/session diff --git a/api/sessionrecording/session_recording_test.go b/api/sessionrecording/session_recording_test.go index 7b6226dcd88d1..001130e5e0b9c 100644 --- a/api/sessionrecording/session_recording_test.go +++ b/api/sessionrecording/session_recording_test.go @@ -18,6 +18,7 @@ package sessionrecording_test import ( "context" + "fmt" "os" "testing" @@ -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 +} diff --git a/api/sessionrecording/testdata/session b/api/sessionrecording/testdata/session new file mode 100644 index 0000000000000000000000000000000000000000..d478b3e8bda704066786716507fc62d0d0228120 GIT binary patch literal 392 zcmZQz00Tw{#o!608RWY;Ak6cuHLyb=PzsPdFp6geDo}1#+Jt) zdg}lG|DP_BG$AP<=|a+mq=F;{76yj@|I6OVa2dc%V_+a)!NyCEgdQh|B