frostfs-http-gw/tree/tree_test.go
Nikita Zinkevich 2e71755d69
All checks were successful
/ DCO (pull_request) Successful in 2m16s
/ Vulncheck (pull_request) Successful in 2m21s
/ Builds (pull_request) Successful in 1m39s
/ Lint (pull_request) Successful in 2m39s
/ Tests (pull_request) Successful in 1m42s
[#166] Change the check of protocol during get object request
Add tree service's GetBucketSettings to use them to check for protocol to use (S3 or native). Also add mock implementations for this methods and GetLatestVersion.

Signed-off-by: Nikita Zinkevich <n.zinkevich@yadro.com>
2024-12-04 15:11:46 +03:00

151 lines
2.7 KiB
Go

package tree
import (
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/data"
"github.com/stretchr/testify/require"
)
type nodeMeta struct {
key string
value []byte
}
func (m nodeMeta) GetKey() string {
return m.key
}
func (m nodeMeta) GetValue() []byte {
return m.value
}
type nodeResponse struct {
meta []nodeMeta
timestamp []uint64
}
func (n nodeResponse) GetTimestamp() []uint64 {
return n.timestamp
}
func (n nodeResponse) GetMeta() []data.Meta {
res := make([]data.Meta, len(n.meta))
for i, value := range n.meta {
res[i] = value
}
return res
}
func (n nodeResponse) GetNodeID() []uint64 {
return nil
}
func (n nodeResponse) GetParentID() []uint64 {
return nil
}
func TestGetLatestNode(t *testing.T) {
for _, tc := range []struct {
name string
nodes []data.NodeResponse
exceptedOID string
error bool
}{
{
name: "empty",
nodes: []data.NodeResponse{},
error: true,
},
{
name: "one node of the object version",
nodes: []data.NodeResponse{
nodeResponse{
timestamp: []uint64{1},
meta: []nodeMeta{
{
key: oidKV,
value: []byte("oid1"),
},
},
},
},
exceptedOID: "oid1",
},
{
name: "one node of the object version and one node of the secondary object",
nodes: []data.NodeResponse{
nodeResponse{
timestamp: []uint64{3},
meta: []nodeMeta{},
},
nodeResponse{
timestamp: []uint64{1},
meta: []nodeMeta{
{
key: oidKV,
value: []byte("oid1"),
},
},
},
},
exceptedOID: "oid1",
},
{
name: "all nodes represent a secondary object",
nodes: []data.NodeResponse{
nodeResponse{
timestamp: []uint64{3},
meta: []nodeMeta{},
},
nodeResponse{
timestamp: []uint64{5},
meta: []nodeMeta{},
},
},
error: true,
},
{
name: "several nodes of different types and with different timestamp",
nodes: []data.NodeResponse{
nodeResponse{
timestamp: []uint64{1},
meta: []nodeMeta{
{
key: oidKV,
value: []byte("oid1"),
},
},
},
nodeResponse{
timestamp: []uint64{3},
meta: []nodeMeta{},
},
nodeResponse{
timestamp: []uint64{4},
meta: []nodeMeta{
{
key: oidKV,
value: []byte("oid2"),
},
},
},
nodeResponse{
timestamp: []uint64{6},
meta: []nodeMeta{},
},
},
exceptedOID: "oid2",
},
} {
t.Run(tc.name, func(t *testing.T) {
actualNode, err := getLatestVersionNode(tc.nodes)
if tc.error {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Equal(t, tc.exceptedOID, string(actualNode.GetMeta()[0].GetValue()))
})
}
}