WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type catalogStub struct {
|
||||
resource *types.StoredResource
|
||||
ref string
|
||||
}
|
||||
|
||||
func (c *catalogStub) Register(
|
||||
_ context.Context,
|
||||
tenantID uint64,
|
||||
physicalPath string,
|
||||
meta interfaces.ResourceRegistration,
|
||||
) (string, error) {
|
||||
c.resource = &types.StoredResource{
|
||||
ID: "resource-1",
|
||||
Handle: "AbCdEfGhIjKlMnOpQrStUv",
|
||||
TenantID: tenantID,
|
||||
PhysicalPath: physicalPath,
|
||||
OriginalName: meta.OriginalName,
|
||||
}
|
||||
c.ref = types.BuildResourcePath(c.resource.Handle)
|
||||
return c.ref, nil
|
||||
}
|
||||
|
||||
func (c *catalogStub) Resolve(_ context.Context, _ string) (*types.StoredResource, error) {
|
||||
return c.resource, nil
|
||||
}
|
||||
|
||||
func (c *catalogStub) ResolvePath(_ context.Context, value string) (string, *types.StoredResource, error) {
|
||||
if value == c.ref {
|
||||
return c.resource.PhysicalPath, c.resource, nil
|
||||
}
|
||||
return value, nil, nil
|
||||
}
|
||||
func (c *catalogStub) Bind(context.Context, string, string, string, string) error { return nil }
|
||||
func (c *catalogStub) MarkDeleted(context.Context, string) error { return nil }
|
||||
|
||||
func (c *catalogStub) Release(context.Context, string, string, string) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
func (c *catalogStub) CreateAccessGrant(context.Context, string, time.Duration) (string, error) {
|
||||
return "GrantTokenAbCdEfGhIjKl", nil
|
||||
}
|
||||
|
||||
func (c *catalogStub) ResolveAccessGrant(context.Context, string) (*types.StoredResource, error) {
|
||||
return c.resource, nil
|
||||
}
|
||||
|
||||
type physicalFileStub struct {
|
||||
savedPath string
|
||||
readPath string
|
||||
}
|
||||
|
||||
func (s *physicalFileStub) CheckConnectivity(context.Context) error { return nil }
|
||||
func (s *physicalFileStub) SaveFile(context.Context, *multipart.FileHeader, uint64, string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (s *physicalFileStub) SaveBytes(context.Context, []byte, uint64, string, bool) (string, error) {
|
||||
return s.savedPath, nil
|
||||
}
|
||||
|
||||
func (s *physicalFileStub) GetFile(_ context.Context, path string) (io.ReadCloser, error) {
|
||||
s.readPath = path
|
||||
return io.NopCloser(strings.NewReader("body")), nil
|
||||
}
|
||||
func (s *physicalFileStub) GetFileURL(context.Context, string) (string, error) { return "", nil }
|
||||
func (s *physicalFileStub) DeleteFile(context.Context, string) error { return nil }
|
||||
func (s *physicalFileStub) CopyFile(context.Context, string, uint64, string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func TestResourceCatalogFileServiceReturnsReferenceAndResolvesReads(t *testing.T) {
|
||||
inner := &physicalFileStub{savedPath: "local://7/exports/a.png"}
|
||||
catalog := &catalogStub{}
|
||||
svc := NewResourceCatalogFileService(inner, catalog)
|
||||
|
||||
ref, err := svc.SaveBytes(context.Background(), []byte("image"), 7, "a.png", false)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "resource://AbCdEfGhIjKlMnOpQrStUv", ref)
|
||||
reader, err := svc.GetFile(context.Background(), ref)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, reader.Close())
|
||||
require.Equal(t, inner.savedPath, inner.readPath)
|
||||
}
|
||||
|
||||
func TestResourceCatalogFileServiceReturnsShortExternalGrantURL(t *testing.T) {
|
||||
t.Setenv("APP_EXTERNAL_URL", "https://weknora.example.com/")
|
||||
inner := &physicalFileStub{savedPath: "local://7/exports/a.png"}
|
||||
catalog := &catalogStub{}
|
||||
svc := NewResourceCatalogFileService(inner, catalog)
|
||||
|
||||
ref, err := svc.SaveBytes(context.Background(), []byte("image"), 7, "a.png", false)
|
||||
require.NoError(t, err)
|
||||
externalURL, err := svc.GetFileURL(context.Background(), ref)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "https://weknora.example.com/r/GrantTokenAbCdEfGhIjKl", externalURL)
|
||||
}
|
||||
Reference in New Issue
Block a user