-
Notifications
You must be signed in to change notification settings - Fork 0
feat(model): report storage engine in tracking metadata #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,6 +32,28 @@ func TestBuildTrackingData(t *testing.T) { | |||||||
| require.Equal(t, 42, res.Data[0].PPID) | ||||||||
| require.Equal(t, "h", res.Meta.Hostname) | ||||||||
| require.Equal(t, "bash", res.Meta.Shell) | ||||||||
| require.Equal(t, StorageEngineBolt, res.Meta.CliEngine) | ||||||||
| } | ||||||||
|
|
||||||||
| func TestBuildTrackingDataFileEngine(t *testing.T) { | ||||||||
| t.Setenv("HOME", t.TempDir()) | ||||||||
| InitFolder("") // reset globals to the default .shelltime under the temp HOME | ||||||||
|
Comment on lines
+39
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoding the 'HOME' environment variable is platform-dependent and violates the general rule of avoiding environment variables like '$HOME' for path resolution. It will fail on Windows where 'os.UserHomeDir()' looks up 'USERPROFILE'. Since 'InitFolder' accepts a custom path, pass 't.TempDir()' directly to it to ensure platform independence.
Suggested change
References
|
||||||||
|
|
||||||||
| store := NewFileStore() | ||||||||
| defer store.Close() | ||||||||
|
|
||||||||
| ctx := context.Background() | ||||||||
| start := time.Now() | ||||||||
| cmd := Command{Shell: "zsh", SessionID: 3, Command: "ls -la", Username: "u", Hostname: "h", Time: start} | ||||||||
| require.NoError(t, store.SavePre(ctx, cmd, start)) | ||||||||
| post := cmd | ||||||||
| post.Time = start.Add(time.Second) | ||||||||
| require.NoError(t, store.SavePost(ctx, post, 0, post.Time)) | ||||||||
|
|
||||||||
| res, err := BuildTrackingData(ctx, store, ShellTimeConfig{}) | ||||||||
| require.NoError(t, err) | ||||||||
| require.Len(t, res.Data, 1) | ||||||||
| require.Equal(t, StorageEngineFile, res.Meta.CliEngine) | ||||||||
| } | ||||||||
|
|
||||||||
| func TestBuildTrackingDataExcludes(t *testing.T) { | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring the error from 'json.NewDecoder().Decode()' can lead to silent test failures or confusing assertion errors if the request body is malformed or empty. It is better to explicitly assert that decoding succeeded.