[#233] Fix browsing
All checks were successful
/ DCO (pull_request) Successful in 39s
/ Vulncheck (pull_request) Successful in 59s
/ Builds (pull_request) Successful in 51s
/ OCI image (pull_request) Successful in 1m29s
/ Lint (pull_request) Successful in 2m27s
/ Tests (pull_request) Successful in 1m30s
/ Integration tests (pull_request) Successful in 6m10s
/ Vulncheck (push) Successful in 58s
/ Builds (push) Successful in 1m4s
/ OCI image (push) Successful in 1m28s
/ Lint (push) Successful in 2m13s
/ Tests (push) Successful in 1m11s
/ Integration tests (push) Successful in 5m56s
All checks were successful
/ DCO (pull_request) Successful in 39s
/ Vulncheck (pull_request) Successful in 59s
/ Builds (pull_request) Successful in 51s
/ OCI image (pull_request) Successful in 1m29s
/ Lint (pull_request) Successful in 2m27s
/ Tests (pull_request) Successful in 1m30s
/ Integration tests (pull_request) Successful in 6m10s
/ Vulncheck (push) Successful in 58s
/ Builds (push) Successful in 1m4s
/ OCI image (push) Successful in 1m28s
/ Lint (push) Successful in 2m13s
/ Tests (push) Successful in 1m11s
/ Integration tests (push) Successful in 5m56s
Simplify tree listing (we need only nodes in exactly the same parent level) Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
e579549b41
commit
dbb1bcad00
11 changed files with 302 additions and 151 deletions
|
@ -14,9 +14,10 @@ import (
|
|||
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/cache"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/data"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/handler/middleware"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/layer"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/templates"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/resolver"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/tokens"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/tree"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/utils"
|
||||
v2container "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/container"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
||||
|
@ -36,32 +37,6 @@ import (
|
|||
"go.uber.org/zap/zaptest"
|
||||
)
|
||||
|
||||
type treeServiceMock struct {
|
||||
system map[string]map[string]*data.BaseNodeVersion
|
||||
}
|
||||
|
||||
func newTreeService() *treeServiceMock {
|
||||
return &treeServiceMock{
|
||||
system: make(map[string]map[string]*data.BaseNodeVersion),
|
||||
}
|
||||
}
|
||||
|
||||
func (t *treeServiceMock) CheckSettingsNodeExists(context.Context, *data.BucketInfo) error {
|
||||
_, ok := t.system["bucket-settings"]
|
||||
if !ok {
|
||||
return layer.ErrNodeNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *treeServiceMock) GetSubTreeByPrefix(context.Context, *data.BucketInfo, string, bool) ([]data.NodeInfo, string, error) {
|
||||
return nil, "", nil
|
||||
}
|
||||
|
||||
func (t *treeServiceMock) GetLatestVersion(context.Context, *cid.ID, string) (*data.NodeVersion, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type configMock struct {
|
||||
additionalFilenameSearch bool
|
||||
additionalSlashSearch bool
|
||||
|
@ -82,7 +57,7 @@ func (c *configMock) IndexPageEnabled() bool {
|
|||
}
|
||||
|
||||
func (c *configMock) IndexPageTemplate() string {
|
||||
return ""
|
||||
return templates.DefaultIndexTemplate
|
||||
}
|
||||
|
||||
func (c *configMock) IndexPageNativeTemplate() string {
|
||||
|
@ -124,7 +99,7 @@ type handlerContext struct {
|
|||
|
||||
h *Handler
|
||||
frostfs *TestFrostFS
|
||||
tree *treeServiceMock
|
||||
tree *treeServiceClientMock
|
||||
cfg *configMock
|
||||
}
|
||||
|
||||
|
@ -174,14 +149,14 @@ func prepareHandlerContextBase(logger *zap.Logger) (*handlerContext, error) {
|
|||
}),
|
||||
}
|
||||
|
||||
treeMock := newTreeService()
|
||||
treeMock := newTreeServiceClientMock()
|
||||
cfgMock := &configMock{}
|
||||
|
||||
workerPool, err := ants.NewPool(1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
handler := New(params, cfgMock, treeMock, workerPool)
|
||||
handler := New(params, cfgMock, tree.NewTree(treeMock, logger), workerPool)
|
||||
|
||||
return &handlerContext{
|
||||
key: key,
|
||||
|
@ -532,6 +507,100 @@ func TestGetObjectWithFallback(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestIndex(t *testing.T) {
|
||||
ctx := middleware.SetNamespace(context.Background(), "")
|
||||
|
||||
t.Run("s3", func(t *testing.T) {
|
||||
hc, cnrID := prepareHandlerAndBucket(t)
|
||||
|
||||
obj1ID := oidtest.ID()
|
||||
obj1 := object.New()
|
||||
obj1.SetID(obj1ID)
|
||||
obj1.SetPayload([]byte("obj1"))
|
||||
obj1.SetAttributes(prepareObjectAttributes(object.AttributeFilePath, "prefix/obj1"))
|
||||
hc.frostfs.objects[cnrID.String()+"/"+obj1ID.String()] = obj1
|
||||
|
||||
hc.tree.containers[cnrID.String()] = containerInfo{
|
||||
trees: map[string]map[string]nodeResponse{
|
||||
"system": {"bucket-settings": nodeResponse{nodeID: 1}},
|
||||
"version": {
|
||||
"": nodeResponse{}, //root
|
||||
"prefix": nodeResponse{
|
||||
nodeID: 1,
|
||||
meta: []nodeMeta{{key: tree.FileNameKey, value: []byte("prefix")}}},
|
||||
"obj1": nodeResponse{
|
||||
parentID: 1,
|
||||
nodeID: 2,
|
||||
meta: []nodeMeta{
|
||||
{key: tree.FileNameKey, value: []byte("obj1")},
|
||||
{key: "OID", value: []byte(obj1ID.String())},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
r := prepareGetRequest(ctx, cnrID.EncodeToString(), "prefix/")
|
||||
hc.Handler().DownloadByAddressOrBucketName(r)
|
||||
require.Equal(t, fasthttp.StatusNotFound, r.Response.StatusCode())
|
||||
|
||||
r = prepareGetRequest(ctx, cnrID.EncodeToString(), "prefix")
|
||||
hc.Handler().DownloadByAddressOrBucketName(r)
|
||||
require.Equal(t, fasthttp.StatusNotFound, r.Response.StatusCode())
|
||||
|
||||
hc.cfg.indexEnabled = true
|
||||
|
||||
r = prepareGetRequest(ctx, cnrID.EncodeToString(), "prefix")
|
||||
hc.Handler().DownloadByAddressOrBucketName(r)
|
||||
require.Contains(t, string(r.Response.Body()), "Index of s3://bucket/prefix")
|
||||
require.Contains(t, string(r.Response.Body()), obj1ID.String())
|
||||
|
||||
r = prepareGetRequest(ctx, cnrID.EncodeToString(), "prefix/")
|
||||
hc.Handler().DownloadByAddressOrBucketName(r)
|
||||
require.Contains(t, string(r.Response.Body()), "Index of s3://bucket/prefix")
|
||||
require.Contains(t, string(r.Response.Body()), obj1ID.String())
|
||||
|
||||
r = prepareGetRequest(ctx, "bucket", "dummy")
|
||||
hc.Handler().DownloadByAddressOrBucketName(r)
|
||||
require.Contains(t, string(r.Response.Body()), "Index of s3://bucket/dummy")
|
||||
})
|
||||
|
||||
t.Run("native", func(t *testing.T) {
|
||||
hc, cnrID := prepareHandlerAndBucket(t)
|
||||
|
||||
obj1ID := oidtest.ID()
|
||||
obj1 := object.New()
|
||||
obj1.SetID(obj1ID)
|
||||
obj1.SetPayload([]byte("obj1"))
|
||||
obj1.SetAttributes(prepareObjectAttributes(object.AttributeFilePath, "prefix/obj1"))
|
||||
hc.frostfs.objects[cnrID.String()+"/"+obj1ID.String()] = obj1
|
||||
|
||||
r := prepareGetRequest(ctx, cnrID.EncodeToString(), "prefix/")
|
||||
hc.Handler().DownloadByAddressOrBucketName(r)
|
||||
require.Equal(t, fasthttp.StatusNotFound, r.Response.StatusCode())
|
||||
|
||||
r = prepareGetRequest(ctx, cnrID.EncodeToString(), "prefix")
|
||||
hc.Handler().DownloadByAddressOrBucketName(r)
|
||||
require.Equal(t, fasthttp.StatusNotFound, r.Response.StatusCode())
|
||||
|
||||
hc.cfg.indexEnabled = true
|
||||
|
||||
r = prepareGetRequest(ctx, cnrID.EncodeToString(), "prefix")
|
||||
hc.Handler().DownloadByAddressOrBucketName(r)
|
||||
require.Contains(t, string(r.Response.Body()), "Index of frostfs://"+cnrID.String()+"/prefix")
|
||||
require.Contains(t, string(r.Response.Body()), obj1ID.String())
|
||||
|
||||
r = prepareGetRequest(ctx, cnrID.EncodeToString(), "prefix/")
|
||||
hc.Handler().DownloadByAddressOrBucketName(r)
|
||||
require.Contains(t, string(r.Response.Body()), "Index of frostfs://"+cnrID.String()+"/prefix")
|
||||
require.Contains(t, string(r.Response.Body()), obj1ID.String())
|
||||
|
||||
r = prepareGetRequest(ctx, cnrID.EncodeToString(), "dummy")
|
||||
hc.Handler().DownloadByAddressOrBucketName(r)
|
||||
require.Contains(t, string(r.Response.Body()), "Index of frostfs://"+cnrID.String()+"/dummy")
|
||||
})
|
||||
}
|
||||
|
||||
func prepareUploadRequest(ctx context.Context, bucket, content string) (*fasthttp.RequestCtx, error) {
|
||||
r := new(fasthttp.RequestCtx)
|
||||
utils.SetContextToRequest(ctx, r)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue