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

Function testAdvancedQuery

client/integration_test.go:355–537  ·  view source on GitHub ↗
(t *testing.T, tester shellTester)

Source from the content-addressed store, hash-verified

353}
354
355func testAdvancedQuery(t *testing.T, tester shellTester) {
356 // Set up
357 defer testutils.BackupAndRestore(t)()
358
359 // Install hishtory
360 userSecret := installHishtory(t, tester, "")
361
362 // Run some commands we can query for
363 _, err := tester.RunInteractiveShellRelaxed(t, `echo nevershouldappear
364notacommand
365cd /tmp/
366echo querybydir
367hishtory disable`)
368 require.NoError(t, err)
369
370 // A super basic query just to ensure the basics are working
371 out := hishtoryQuery(t, tester, `echo`)
372 require.Contains(t, out, "echo querybydir")
373 require.Contains(t, out, "echo nevershouldappear")
374 if strings.Count(out, "\n") != 3 {
375 t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out)
376 }
377
378 // Query based on cwd
379 out = hishtoryQuery(t, tester, `cwd:/tmp`)
380 require.Contains(t, out, "echo querybydir", "hishtory query doesn't contain result matching cwd:/tmp")
381 require.NotContains(t, out, "nevershouldappear")
382 if strings.Count(out, "\n") != 4 {
383 t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out)
384 }
385 // And again, but with a strailing slash
386 out = hishtoryQuery(t, tester, `cwd:/tmp/`)
387 require.Contains(t, out, "echo querybydir", "hishtory query doesn't contain result matching cwd:/tmp/")
388 require.NotContains(t, out, "nevershouldappear")
389 if strings.Count(out, "\n") != 4 {
390 t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out)
391 }
392
393 // Query based on cwd without the slash
394 out = hishtoryQuery(t, tester, `cwd:tmp`)
395 require.Contains(t, out, "echo querybydir")
396 if strings.Count(out, "\n") != 4 {
397 t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out)
398 }
399
400 // Query based on cwd and another term
401 out = hishtoryQuery(t, tester, `cwd:/tmp querybydir`)
402 require.Contains(t, out, "echo querybydir")
403 require.NotContains(t, out, "nevershouldappear")
404 if strings.Count(out, "\n") != 2 {
405 t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out)
406 }
407
408 // Query based on exit_code
409 out = hishtoryQuery(t, tester, `exit_code:127`)
410 require.Contains(t, out, "notacommand")
411 if strings.Count(out, "\n") != 2 {
412 t.Fatalf("hishtory query has the wrong number of lines=%d, out=%#v", strings.Count(out, "\n"), out)

Callers 1

TestParamFunction · 0.85

Calls 7

BackupAndRestoreFunction · 0.92
MakeFakeHistoryEntryFunction · 0.92
installHishtoryFunction · 0.85
hishtoryQueryFunction · 0.85
RunInteractiveShellMethod · 0.65

Tested by

no test coverage detected