mirror of
https://github.com/MengMengCode/VoCat.git
synced 2026-08-18 22:03:44 +08:00
32 lines
849 B
Go
32 lines
849 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestInstallerValidatesDatabaseBeforeReplacingBinary(t *testing.T) {
|
|
scriptBytes, err := os.ReadFile("../../scripts/install.sh")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
script := string(scriptBytes)
|
|
mainStart := strings.LastIndex(script, "# --- Main ")
|
|
if mainStart < 0 {
|
|
t.Fatal("installer main section not found")
|
|
}
|
|
main := script[mainStart:]
|
|
validateAt := strings.Index(main, `bootstrap_admin "${VOCAT_TMP}/vocat"`)
|
|
installAt := strings.Index(main, "install_binary")
|
|
if validateAt < 0 {
|
|
t.Fatal("installer does not validate the database with the downloaded binary")
|
|
}
|
|
if installAt < 0 {
|
|
t.Fatal("installer does not install the downloaded binary")
|
|
}
|
|
if validateAt > installAt {
|
|
t.Fatal("installer replaces the current binary before validating database compatibility")
|
|
}
|
|
}
|