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

Function testIntegrationWithNewDevice

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

Source from the content-addressed store, hash-verified

144}
145
146func testIntegrationWithNewDevice(t *testing.T, tester shellTester) {
147 // Set up
148 defer testutils.BackupAndRestore(t)()
149
150 // Run the test
151 userSecret := testBasicUserFlow(t, tester, Online)
152
153 // Install it again
154 testutils.ResetLocalState(t)
155 installHishtory(t, tester, userSecret)
156
157 // Querying should show the history from the previous run
158 out := tester.RunInteractiveShell(t, `hishtory query`)
159 expected := []string{"echo thisisrecorded", "hishtory enable", "echo bar", "echo foo", "ls /foo", "ls /bar", "ls /a"}
160 for _, item := range expected {
161 require.Contains(t, out, item)
162 if strings.Count(out, item) != 1 {
163 t.Fatalf("output has %#v in it multiple times! out=%#v", item, out)
164 }
165 }
166
167 tester.RunInteractiveShell(t, "echo mynewcommand")
168 out = hishtoryQuery(t, tester, "")
169 require.Contains(t, out, "echo mynewcommand")
170 if strings.Count(out, "echo mynewcommand") != 1 {
171 t.Fatalf("output has `echo mynewcommand` the wrong number of times")
172 }
173
174 // Install it a 3rd time
175 testutils.ResetLocalState(t)
176 installHishtory(t, tester, "adifferentsecret")
177
178 // Run a command that shouldn't be in the hishtory later on
179 tester.RunInteractiveShell(t, `echo notinthehistory`)
180 out = hishtoryQuery(t, tester, "")
181 require.Contains(t, out, "echo notinthehistory")
182 require.NotContains(t, out, "mynewcommand")
183 require.NotContains(t, out, "thisisrecorded")
184
185 // Set the secret key to the previous secret key
186 out, err := tester.RunInteractiveShellRelaxed(t, ` export HISHTORY_SKIP_INIT_IMPORT=1
187yes | hishtory init `+userSecret)
188 require.NoError(t, err)
189 require.Contains(t, out, "Setting secret hishtory key to "+userSecret, "Failed to re-init with the user secret")
190
191 // Querying shouldn't show the entry from the previous account
192 out = hishtoryQuery(t, tester, "")
193 require.NotContains(t, out, "notinthehistory", "output contains the unexpected item: notinthehistory")
194
195 // And it should show the history from the previous run on this account
196 expected = []string{"echo thisisrecorded", "echo mynewcommand", "hishtory enable", "echo bar", "echo foo", "ls /foo", "ls /bar", "ls /a"}
197 for _, item := range expected {
198 require.Contains(t, out, item, "output is missing expected item")
199 if strings.Count(out, item) != 1 {
200 t.Fatalf("output has %#v in it multiple times! out=%#v", item, out)
201 }
202 }
203

Callers 1

TestParamFunction · 0.85

Calls 12

BackupAndRestoreFunction · 0.92
ResetLocalStateFunction · 0.92
MakeFakeHistoryEntryFunction · 0.92
CompareGoldensFunction · 0.92
testBasicUserFlowFunction · 0.85
installHishtoryFunction · 0.85
hishtoryQueryFunction · 0.85
RunInteractiveShellMethod · 0.65
ShellNameMethod · 0.65

Tested by

no test coverage detected