(t *testing.T, tester shellTester, installInitialVersion func(*testing.T, shellTester) (string, string), installUpdatedVersion func(*testing.T, shellTester) string)
| 595 | } |
| 596 | |
| 597 | func testGenericUpdate(t *testing.T, tester shellTester, installInitialVersion func(*testing.T, shellTester) (string, string), installUpdatedVersion func(*testing.T, shellTester) string) { |
| 598 | defer testutils.BackupAndRestoreEnv("HISHTORY_FORCE_CLIENT_VERSION")() |
| 599 | if !testutils.IsOnline() { |
| 600 | t.Skip("skipping because we're currently offline") |
| 601 | } |
| 602 | if runtime.GOOS == "linux" && runtime.GOARCH == "arm64" { |
| 603 | t.Skip("skipping on linux/arm64 which is unsupported") |
| 604 | } |
| 605 | // Set up |
| 606 | defer testutils.BackupAndRestore(t)() |
| 607 | userSecret, initialVersion := installInitialVersion(t, tester) |
| 608 | |
| 609 | // Record a command before the update |
| 610 | tester.RunInteractiveShell(t, "echo hello") |
| 611 | |
| 612 | // Check the status command |
| 613 | out := tester.RunInteractiveShell(t, `hishtory status`) |
| 614 | require.Contains(t, out, fmt.Sprintf("hiSHtory: %s\nEnabled: true\nSecret Key: %s\nCommit Hash: ", initialVersion, userSecret)) |
| 615 | if initialVersion == "v0.Unknown" { |
| 616 | require.Contains(t, out, "Commit Hash: Unknown") |
| 617 | } else { |
| 618 | require.NotContains(t, out, "Commit Hash: Unknown") |
| 619 | } |
| 620 | |
| 621 | // Update |
| 622 | updatedVersion := installUpdatedVersion(t, tester) |
| 623 | |
| 624 | // Then check the status command again to confirm the update worked |
| 625 | out = tester.RunInteractiveShell(t, `hishtory status`) |
| 626 | require.Contains(t, out, fmt.Sprintf("\nEnabled: true\nSecret Key: %s\nCommit Hash: ", userSecret)) |
| 627 | if updatedVersion != "v0.Unknown" { |
| 628 | require.NotContains(t, out, "\nCommit Hash: Unknown\n") |
| 629 | } |
| 630 | |
| 631 | // Check that the history was preserved after the update |
| 632 | out = tester.RunInteractiveShell(t, "hishtory export -pipefail | grep -v '/tmp/client install'") |
| 633 | expectedOutput := "echo hello\nhishtory status\necho postupdate\nhishtory status\n" |
| 634 | if diff := cmp.Diff(expectedOutput, out); diff != "" { |
| 635 | t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out) |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | func testRepeatedCommandThenQuery(t *testing.T, tester shellTester) { |
| 640 | // Set up |
no test coverage detected