MCPcopy
hub / github.com/ddworken/hishtory / testBasicUserFlow

Function testBasicUserFlow

client/integration_test.go:255–353  ·  view source on GitHub ↗
(t *testing.T, tester shellTester, onlineStatus OnlineStatus)

Source from the content-addressed store, hash-verified

253}
254
255func testBasicUserFlow(t *testing.T, tester shellTester, onlineStatus OnlineStatus) string {
256 // Test install
257 userSecret := installWithOnlineStatus(t, tester, onlineStatus)
258 assertOnlineStatus(t, onlineStatus)
259
260 // Test the status subcommand
261 out := tester.RunInteractiveShell(t, `hishtory status`)
262 if out != fmt.Sprintf("hiSHtory: v0.Unknown\nEnabled: true\nSecret Key: %s\nCommit Hash: Unknown\n", userSecret) {
263 t.Fatalf("status command has unexpected output: %#v", out)
264 }
265
266 // Assert that hishtory is correctly using the dev config.sh
267 homedir, err := os.UserHomeDir()
268 require.NoError(t, err)
269 dat, err := os.ReadFile(path.Join(homedir, data.GetHishtoryPath(), "config.sh"))
270 require.NoError(t, err, "failed to read config.sh")
271 require.NotContains(t, string(dat), "# Background Run", "config.sh is the prod version when it shouldn't be")
272
273 // Test the banner
274 if onlineStatus == Online {
275 os.Setenv("FORCED_BANNER", "HELLO_FROM_SERVER")
276 defer os.Setenv("FORCED_BANNER", "")
277 out = hishtoryQuery(t, tester, "")
278 require.Contains(t, out, "HELLO_FROM_SERVER\nHostname", "hishtory query didn't show the banner message")
279 os.Setenv("FORCED_BANNER", "")
280 }
281
282 // Test recording commands
283 out, err = tester.RunInteractiveShellRelaxed(t, `ls /a
284ls /bar
285ls /foo
286echo foo
287echo bar
288hishtory disable
289echo thisisnotrecorded
290sleep 0.5
291hishtory enable
292echo thisisrecorded`)
293 require.NoError(t, err)
294 if out != "foo\nbar\nthisisnotrecorded\nthisisrecorded\n" {
295 t.Fatalf("unexpected output from running commands: %#v", out)
296 }
297
298 // Test querying for all commands
299 out = hishtoryQuery(t, tester, "")
300 expected := []string{"echo thisisrecorded", "hishtory enable", "echo bar", "echo foo", "ls /foo", "ls /bar", "ls /a"}
301 for _, item := range expected {
302 require.Contains(t, out, item, "output is missing expected item")
303 }
304
305 // Test the actual table output
306 hostnameMatcher := `\S+`
307 tableDividerMatcher := `\s+`
308 pathMatcher := `~?/[a-zA-Z_0-9/-]+`
309 datetimeMatcher := `[a-zA-Z]{3}\s\d{1,2}\s\d{4}\s[0-9:]+\s([A-Z]{3}|[+-]\d{4})`
310 runtimeMatcher := `[0-9.ms]+`
311 exitCodeMatcher := `0`
312 pipefailMatcher := `set -em?o pipefail`

Callers 2

testIntegrationFunction · 0.85

Calls 7

GetHishtoryPathFunction · 0.92
installWithOnlineStatusFunction · 0.85
assertOnlineStatusFunction · 0.85
hishtoryQueryFunction · 0.85
RunInteractiveShellMethod · 0.65

Tested by

no test coverage detected