mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-24 04:55:50 +02:00
Add import-json and export-json commands for importing and exporting fully detailed histories (#271)
This commit is contained in:
@@ -3435,4 +3435,39 @@ func TestStatusFullConfig(t *testing.T) {
|
||||
testutils.CompareGoldens(t, out, "TestStatusFullConfig")
|
||||
}
|
||||
|
||||
func TestExportJson(t *testing.T) {
|
||||
markTestForSharding(t, 20)
|
||||
defer testutils.BackupAndRestore(t)()
|
||||
tester := zshTester{}
|
||||
installHishtory(t, tester, "")
|
||||
|
||||
// Create some history entries
|
||||
db := hctx.GetDb(hctx.MakeContext())
|
||||
e1 := testutils.MakeFakeHistoryEntry("echo synth1")
|
||||
e1.StartTime = time.Unix(1234567, 0)
|
||||
require.NoError(t, db.Create(e1).Error)
|
||||
e2 := testutils.MakeFakeHistoryEntry("echo synth2")
|
||||
e1.StartTime = time.Unix(1244567, 0)
|
||||
require.NoError(t, db.Create(e2).Error)
|
||||
|
||||
// Run export-json
|
||||
out := tester.RunInteractiveShell(t, `hishtory export-json | grep synth | grep -v export-json`)
|
||||
testutils.CompareGoldens(t, out, "TestExportJson")
|
||||
}
|
||||
|
||||
func TestImportJson(t *testing.T) {
|
||||
markTestForSharding(t, 20)
|
||||
defer testutils.BackupAndRestore(t)()
|
||||
tester := zshTester{}
|
||||
installHishtory(t, tester, "")
|
||||
|
||||
// Run an import with the export-json golden
|
||||
out := tester.RunInteractiveShell(t, `cat client/testdata/TestExportJson | hishtory import-json`)
|
||||
require.Equal(t, "Imported 2 history entries\n", out)
|
||||
|
||||
// Run export-json
|
||||
out = tester.RunInteractiveShell(t, `hishtory export-json | grep synth | grep -v export-json`)
|
||||
testutils.CompareGoldens(t, out, "TestExportJson")
|
||||
}
|
||||
|
||||
// TODO: somehow test/confirm that hishtory works even if only bash/only zsh is installed
|
||||
|
Reference in New Issue
Block a user