Add a Check for updates button under Settings; keep the self edge when settings are saved
CI / test (push) Successful in 4m48s
CI / test (push) Successful in 4m48s
Saving settings replaced the whole Settings value, which would have dropped SelfEdgeID and made the next start create a second self edge with a new token. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
da3d7201a1
commit
abf352e6c9
10 files changed
+135
-1
No files matched your search
@@ -0,0 +1,54 @@
|
||||
package hammerhead
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCheckForUpdates(t *testing.T) {
|
||||
gitea := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/repos/Veillax/hammerhead/releases/latest" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
fmt.Fprint(w, `{"tag_name":"v0.3.0","prerelease":false,"assets":[]}`)
|
||||
}))
|
||||
defer gitea.Close()
|
||||
for _, c := range []struct {
|
||||
version string
|
||||
newer bool
|
||||
}{{"v0.2.0", true}, {"v0.3.0", false}, {"dev", false}} {
|
||||
s, err := New(t.TempDir(), Options{AdminEmail: "admin@test.local", AdminPassword: "password123", MasterKey: key,
|
||||
Version: c.version, UpdateServer: gitea.URL, UpdateRepo: "Veillax/hammerhead", AutoUpdate: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
do := apiClient(t, s)
|
||||
code, b := do("GET", "/api/admin/update", nil)
|
||||
var out struct {
|
||||
Current, Latest, Error string
|
||||
Newer, AutoUpdate bool
|
||||
}
|
||||
json.Unmarshal(b, &out)
|
||||
if code != 200 || out.Current != c.version || out.Latest != "v0.3.0" || out.Newer != c.newer || !out.AutoUpdate || out.Error != "" {
|
||||
t.Errorf("%s: %d %s", c.version, code, b)
|
||||
}
|
||||
s.Close()
|
||||
}
|
||||
|
||||
// an unreachable release server is reported, not fatal
|
||||
s, err := New(t.TempDir(), Options{AdminEmail: "admin@test.local", AdminPassword: "password123", MasterKey: key, Version: "v0.1.0", UpdateServer: "http://127.0.0.1:1"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer s.Close()
|
||||
code, b := apiClient(t, s)("GET", "/api/admin/update", nil)
|
||||
var out struct{ Error string }
|
||||
json.Unmarshal(b, &out)
|
||||
if code != 200 || out.Error == "" {
|
||||
t.Errorf("unreachable server: %d %s", code, b)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user