mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-24 22:11:40 +02:00
Add a test for the install.py script
This commit is contained in:
parent
72bd46d4e8
commit
00f6bed62c
@ -123,6 +123,7 @@ func TestParameterized(t *testing.T) {
|
|||||||
t.Run("testTableDisplayCwd/"+tester.ShellName(), func(t *testing.T) { testTableDisplayCwd(t, tester) })
|
t.Run("testTableDisplayCwd/"+tester.ShellName(), func(t *testing.T) { testTableDisplayCwd(t, tester) })
|
||||||
t.Run("testTimestampsAreReasonablyCorrect/"+tester.ShellName(), func(t *testing.T) { testTimestampsAreReasonablyCorrect(t, tester) })
|
t.Run("testTimestampsAreReasonablyCorrect/"+tester.ShellName(), func(t *testing.T) { testTimestampsAreReasonablyCorrect(t, tester) })
|
||||||
t.Run("testRequestAndReceiveDbDump/"+tester.ShellName(), func(t *testing.T) { testRequestAndReceiveDbDump(t, tester) })
|
t.Run("testRequestAndReceiveDbDump/"+tester.ShellName(), func(t *testing.T) { testRequestAndReceiveDbDump(t, tester) })
|
||||||
|
t.Run("testInstallViaPythonScript/"+tester.ShellName(), func(t *testing.T) { testInstallViaPythonScript(t, tester) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1011,4 +1012,38 @@ echo other`)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testInstallViaPythonScript(t *testing.T, tester shellTester) {
|
||||||
|
// Set up
|
||||||
|
defer shared.BackupAndRestore(t)()
|
||||||
|
|
||||||
|
// Install via the python script
|
||||||
|
out := tester.RunInteractiveShell(t, `curl https://hishtory.dev/install.py | python3 -`)
|
||||||
|
if !strings.Contains(out, "Succesfully installed hishtory") {
|
||||||
|
t.Fatalf("unexpected output when installing hishtory, out=%#v", out)
|
||||||
|
}
|
||||||
|
r := regexp.MustCompile(`Setting secret hishtory key to (.*)`)
|
||||||
|
matches := r.FindStringSubmatch(out)
|
||||||
|
if len(matches) != 2 {
|
||||||
|
t.Fatalf("Failed to extract userSecret from output: matches=%#v", matches)
|
||||||
|
}
|
||||||
|
userSecret := matches[1]
|
||||||
|
|
||||||
|
// Test the status subcommand
|
||||||
|
downloadData, err := lib.GetDownloadData()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
out = tester.RunInteractiveShell(t, `hishtory status`)
|
||||||
|
expectedOut := fmt.Sprintf("Hishtory: %s\nEnabled: true\nSecret Key: %s\nCommit Hash: ", downloadData.Version, userSecret)
|
||||||
|
if !strings.Contains(out, expectedOut) {
|
||||||
|
t.Fatalf("status command has unexpected output: actual=%#v, expected=%#v", out, expectedOut)
|
||||||
|
}
|
||||||
|
|
||||||
|
// And test that it recorded that command
|
||||||
|
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
|
||||||
|
if out != "hishtory status\n" {
|
||||||
|
t.Fatalf("unexpected output from hishtory export=%#v", out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: write a test that runs hishtroy export | grep -v pipefail and then see if that shows up in query/export, I think there is weird behavior here
|
// TODO: write a test that runs hishtroy export | grep -v pipefail and then see if that shows up in query/export, I think there is weird behavior here
|
||||||
|
@ -514,16 +514,24 @@ func copyFile(src, dst string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update() error {
|
func GetDownloadData() (shared.UpdateInfo, error) {
|
||||||
// Download the binary
|
|
||||||
respBody, err := ApiGet("/api/v1/download")
|
respBody, err := ApiGet("/api/v1/download")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to download update info: %v", err)
|
return shared.UpdateInfo{}, fmt.Errorf("failed to download update info: %v", err)
|
||||||
}
|
}
|
||||||
var downloadData shared.UpdateInfo
|
var downloadData shared.UpdateInfo
|
||||||
err = json.Unmarshal(respBody, &downloadData)
|
err = json.Unmarshal(respBody, &downloadData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to parse update info: %v", err)
|
return shared.UpdateInfo{}, fmt.Errorf("failed to parse update info: %v", err)
|
||||||
|
}
|
||||||
|
return downloadData, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Update() error {
|
||||||
|
// Download the binary
|
||||||
|
downloadData, err := GetDownloadData()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
if downloadData.Version == "v0."+Version {
|
if downloadData.Version == "v0."+Version {
|
||||||
fmt.Printf("Latest version (v0.%s) is already installed\n", Version)
|
fmt.Printf("Latest version (v0.%s) is already installed\n", Version)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user