feat: add independent platform modules and multi-provider storage

This commit is contained in:
2026-09-23 14:51:14 +08:00
parent f91034477b
commit 208a9c3fbd
57 changed files with 4890 additions and 48 deletions

35
storage/signed_test.go Normal file
View File

@@ -0,0 +1,35 @@
package storage_test
import (
"context"
"git.yuntuo.hk/k2safe/go-omni/storage"
"git.yuntuo.hk/k2safe/go-omni/storage/local"
"net/http/httptest"
"strings"
"testing"
"time"
)
func TestLocalSignedDownload(t *testing.T) {
s, _ := local.New(t.TempDir(), 64)
s.Put(context.Background(), "file", strings.NewReader("hello"), 5, "text/plain")
signer, _ := storage.NewSigner(s, "https://example.test/download", []byte(strings.Repeat("x", 32)))
u, err := signer.PresignGet(context.Background(), "file", time.Minute)
if err != nil {
t.Fatal(err)
}
request := httptest.NewRequest("GET", u.String(), nil)
response := httptest.NewRecorder()
signer.ServeHTTP(response, request)
if response.Code != 200 || response.Body.String() != "hello" || response.Header().Get("Content-Disposition") != "attachment" {
t.Fatal(response)
}
q := u.Query()
q.Set("key", "another")
u.RawQuery = q.Encode()
response = httptest.NewRecorder()
signer.ServeHTTP(response, httptest.NewRequest("GET", u.String(), nil))
if response.Code != 403 {
t.Fatal(response.Code)
}
}