package policy import ( "fmt" "testing" "git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine" "git.frostfs.info/TrueCloudLab/policy-engine/schema/native" "github.com/stretchr/testify/require" ) func TestTransformNameIfContainer(t *testing.T) { for _, test := range []struct { Name string Target engine.Target }{ { Name: "check namespace", Target: engine.NamespaceTarget("namespace1"), }, { Name: "check ResourceFormatNamespaceObjects", Target: engine.ContainerTarget( fmt.Sprintf(native.ResourceFormatNamespaceObjects, "BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R")), }, { Name: "check ResourceFormatNamespaceContainerObjects", Target: engine.ContainerTarget( fmt.Sprintf(native.ResourceFormatNamespaceContainerObjects, "BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R", "AeZa5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R")), }, { Name: "check ResourceFormatNamespaceContainerObject", Target: engine.ContainerTarget( fmt.Sprintf(native.ResourceFormatNamespaceContainerObject, "BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R", "AeZa5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R", "LxGy5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R")), }, { Name: "check ResourceFormatRootObjects", Target: engine.ContainerTarget(native.ResourceFormatRootObjects), }, { Name: "check ResourceFormatRootContainerObjects", Target: engine.ContainerTarget( fmt.Sprintf(native.ResourceFormatRootContainerObjects, "BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R")), }, { Name: "check ResourceFormatRootContainerObject", Target: engine.ContainerTarget( fmt.Sprintf(native.ResourceFormatRootContainerObject, "BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R", "AeZa5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R")), }, { Name: "check ResourceFormatAllObjects", Target: engine.ContainerTarget(native.ResourceFormatAllObjects), }, { Name: "check ResourceFormatNamespaceContainer", Target: engine.ContainerTarget( fmt.Sprintf(native.ResourceFormatNamespaceContainer, "BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R", "AeZa5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R")), }, { Name: "check ResourceFormatNamespaceContainers", Target: engine.ContainerTarget( fmt.Sprintf(native.ResourceFormatNamespaceContainers, "BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R")), }, { Name: "check ResourceFormatRootContainer", Target: engine.ContainerTarget( fmt.Sprintf(native.ResourceFormatRootContainer, "BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R")), }, { Name: "check ResourceFormatRootContainers", Target: engine.ContainerTarget(native.ResourceFormatRootContainers), }, { Name: "check ResourceFormatAllContainers", Target: engine.ContainerTarget(native.ResourceFormatAllContainers), }, } { t.Run(test.Target.Name, func(t *testing.T) { res := transformNameIfContainer(test.Target) const contractStorageKeyLength = 64 const entityTypeLength = 1 // 'n', 'c' or 'i' require.Less(t, len(res), contractStorageKeyLength-entityTypeLength) }) } }