(t *testing.T, tester shellTester, onlineStatus OnlineStatus)
| 253 | } |
| 254 | |
| 255 | func 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 |
| 284 | ls /bar |
| 285 | ls /foo |
| 286 | echo foo |
| 287 | echo bar |
| 288 | hishtory disable |
| 289 | echo thisisnotrecorded |
| 290 | sleep 0.5 |
| 291 | hishtory enable |
| 292 | echo 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` |
no test coverage detected