2021-01-14 17:39:48 +00:00
|
|
|
package layer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2021-01-14 17:39:48 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-08-13 10:03:49 +00:00
|
|
|
func newTestNodeVersion(id oid.ID, name string) *data.NodeVersion {
|
|
|
|
return &data.NodeVersion{
|
|
|
|
BaseNodeVersion: data.BaseNodeVersion{
|
|
|
|
OID: id,
|
|
|
|
FilePath: name,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTryDirectory(t *testing.T) {
|
2022-04-25 09:57:58 +00:00
|
|
|
var id oid.ID
|
2021-01-14 17:39:48 +00:00
|
|
|
|
|
|
|
cases := []struct {
|
2021-06-29 09:59:33 +00:00
|
|
|
name string
|
|
|
|
prefix string
|
2024-01-17 14:26:02 +00:00
|
|
|
result string
|
2022-08-13 10:03:49 +00:00
|
|
|
node *data.NodeVersion
|
2021-06-29 09:59:33 +00:00
|
|
|
delimiter string
|
2021-01-14 17:39:48 +00:00
|
|
|
}{
|
|
|
|
{
|
2021-06-29 09:59:33 +00:00
|
|
|
name: "small.jpg",
|
2024-01-17 14:26:02 +00:00
|
|
|
result: "",
|
2022-08-13 10:03:49 +00:00
|
|
|
node: newTestNodeVersion(id, "small.jpg"),
|
2021-01-14 17:39:48 +00:00
|
|
|
},
|
|
|
|
{
|
2021-06-29 09:59:33 +00:00
|
|
|
name: "small.jpg not matched prefix",
|
|
|
|
prefix: "big",
|
2024-01-17 14:26:02 +00:00
|
|
|
result: "",
|
2022-08-13 10:03:49 +00:00
|
|
|
node: newTestNodeVersion(id, "small.jpg"),
|
2021-01-14 17:39:48 +00:00
|
|
|
},
|
|
|
|
{
|
2021-06-29 09:59:33 +00:00
|
|
|
name: "small.jpg delimiter",
|
|
|
|
delimiter: "/",
|
2024-01-17 14:26:02 +00:00
|
|
|
result: "",
|
2022-08-13 10:03:49 +00:00
|
|
|
node: newTestNodeVersion(id, "small.jpg"),
|
2021-01-14 17:39:48 +00:00
|
|
|
},
|
|
|
|
{
|
2021-06-29 09:59:33 +00:00
|
|
|
name: "test/small.jpg",
|
2024-01-17 14:26:02 +00:00
|
|
|
result: "",
|
2022-08-13 10:03:49 +00:00
|
|
|
node: newTestNodeVersion(id, "test/small.jpg"),
|
2021-01-14 17:39:48 +00:00
|
|
|
},
|
|
|
|
{
|
2021-06-29 09:59:33 +00:00
|
|
|
name: "test/small.jpg with prefix and delimiter",
|
|
|
|
prefix: "test/",
|
|
|
|
delimiter: "/",
|
2024-01-17 14:26:02 +00:00
|
|
|
result: "",
|
2022-08-13 10:03:49 +00:00
|
|
|
node: newTestNodeVersion(id, "test/small.jpg"),
|
2021-01-14 17:39:48 +00:00
|
|
|
},
|
|
|
|
{
|
2021-06-29 09:59:33 +00:00
|
|
|
name: "a/b/small.jpg",
|
|
|
|
prefix: "a",
|
2024-01-17 14:26:02 +00:00
|
|
|
result: "",
|
2022-08-13 10:03:49 +00:00
|
|
|
node: newTestNodeVersion(id, "a/b/small.jpg"),
|
2021-01-14 17:39:48 +00:00
|
|
|
},
|
|
|
|
{
|
2021-06-29 09:59:33 +00:00
|
|
|
name: "a/b/small.jpg",
|
|
|
|
prefix: "a/",
|
|
|
|
delimiter: "/",
|
2024-01-17 14:26:02 +00:00
|
|
|
result: "a/b/",
|
2022-08-13 10:03:49 +00:00
|
|
|
node: newTestNodeVersion(id, "a/b/small.jpg"),
|
2021-01-14 17:39:48 +00:00
|
|
|
},
|
|
|
|
{
|
2021-06-29 09:59:33 +00:00
|
|
|
name: "a/b/c/small.jpg",
|
|
|
|
prefix: "a/",
|
|
|
|
delimiter: "/",
|
2024-01-17 14:26:02 +00:00
|
|
|
result: "a/b/",
|
2022-08-13 10:03:49 +00:00
|
|
|
node: newTestNodeVersion(id, "a/b/c/small.jpg"),
|
2021-01-14 17:39:48 +00:00
|
|
|
},
|
|
|
|
{
|
2021-06-29 09:59:33 +00:00
|
|
|
name: "a/b/c/small.jpg",
|
|
|
|
prefix: "a/b/c/s",
|
|
|
|
delimiter: "/",
|
2024-01-17 14:26:02 +00:00
|
|
|
result: "",
|
2022-08-13 10:03:49 +00:00
|
|
|
node: newTestNodeVersion(id, "a/b/c/small.jpg"),
|
2021-01-14 17:39:48 +00:00
|
|
|
},
|
|
|
|
{
|
2021-06-29 09:59:33 +00:00
|
|
|
name: "a/b/c/big.jpg",
|
|
|
|
prefix: "a/b/",
|
|
|
|
delimiter: "/",
|
2024-01-17 14:26:02 +00:00
|
|
|
result: "a/b/c/",
|
2022-08-13 10:03:49 +00:00
|
|
|
node: newTestNodeVersion(id, "a/b/c/big.jpg"),
|
2021-01-14 17:39:48 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2021-06-29 09:59:33 +00:00
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2024-01-17 14:26:02 +00:00
|
|
|
dirName := tryDirectoryName(tc.node, tc.prefix, tc.delimiter)
|
|
|
|
require.Equal(t, tc.result, dirName)
|
2021-01-14 17:39:48 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|