chore: migrate mail themes to shared framework and locked upstream inputs
This commit is contained in:
1 parent
5c0589f6f6
commit
fec3ace600
225 files changed
+4718
-15807
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package upstream
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPrepareCacheIsPinnedAndReusableOffline(t *testing.T) {
|
||||
s, err := LoadPinned(filepath.Join("..", ".."))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root := t.TempDir()
|
||||
b, _ := json.Marshal(s.Lock)
|
||||
if err = os.WriteFile(filepath.Join(root, "gitea.lock.json"), b, 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
prefix := "/" + s.Lock.Commit + "/"
|
||||
if !strings.HasPrefix(r.URL.Path, prefix) {
|
||||
t.Errorf("unpinned request %s", r.URL.Path)
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
data, ok := s.Files[strings.TrimPrefix(r.URL.Path, prefix)]
|
||||
if !ok {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
w.Write(data)
|
||||
}))
|
||||
if _, err := prepareFrom(context.Background(), root, server.URL+"/"); err != nil {
|
||||
server.Close()
|
||||
t.Fatal(err)
|
||||
}
|
||||
server.Close()
|
||||
if _, err := prepareFrom(context.Background(), root, server.URL+"/"); err != nil {
|
||||
t.Fatalf("offline cache: %v", err)
|
||||
}
|
||||
path := filepath.Join(CacheDir(root), "templates", "mail", "base", "head.tmpl")
|
||||
if err = os.WriteFile(path, []byte("corrupt"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := prepareFrom(context.Background(), root, server.URL+"/"); err == nil {
|
||||
t.Fatal("corrupt cache was accepted")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user