2024-05-28 09:05:02 +00:00
|
|
|
package ape_test
|
2024-05-06 13:26:51 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-05-28 09:05:02 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/ape"
|
2024-05-06 13:26:51 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2024-10-07 14:20:25 +00:00
|
|
|
apeV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/ape"
|
2024-05-06 13:26:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2024-05-28 09:05:02 +00:00
|
|
|
m = map[ape.TargetType]apeV2.TargetType{
|
|
|
|
ape.TargetTypeUndefined: apeV2.TargetTypeUndefined,
|
|
|
|
ape.TargetTypeNamespace: apeV2.TargetTypeNamespace,
|
|
|
|
ape.TargetTypeContainer: apeV2.TargetTypeContainer,
|
|
|
|
ape.TargetTypeUser: apeV2.TargetTypeUser,
|
|
|
|
ape.TargetTypeGroup: apeV2.TargetTypeGroup,
|
2024-05-06 13:26:51 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTargetType(t *testing.T) {
|
|
|
|
for typesdk, typev2 := range m {
|
|
|
|
t.Run("from sdk to v2 "+typev2.String(), func(t *testing.T) {
|
|
|
|
v2 := typesdk.ToV2()
|
|
|
|
require.Equal(t, v2, typev2)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("from v2 to sdk "+typev2.String(), func(t *testing.T) {
|
2024-05-28 09:05:02 +00:00
|
|
|
var typ ape.TargetType
|
2024-05-06 13:26:51 +00:00
|
|
|
typ.FromV2(typev2)
|
|
|
|
require.Equal(t, typesdk, typ)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestChainTarget(t *testing.T) {
|
|
|
|
var (
|
2024-05-28 09:05:02 +00:00
|
|
|
typ = ape.TargetTypeNamespace
|
2024-05-06 13:26:51 +00:00
|
|
|
name = "namespaceXXYYZZ"
|
|
|
|
)
|
|
|
|
|
|
|
|
t.Run("from sdk to v2", func(t *testing.T) {
|
2024-05-28 09:05:02 +00:00
|
|
|
ct := ape.ChainTarget{
|
2024-05-06 13:26:51 +00:00
|
|
|
TargetType: typ,
|
|
|
|
Name: name,
|
|
|
|
}
|
|
|
|
|
|
|
|
v2 := ct.ToV2()
|
|
|
|
require.Equal(t, m[typ], v2.GetTargetType())
|
|
|
|
require.Equal(t, name, v2.GetName())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("from v2 to sdk", func(t *testing.T) {
|
2024-05-28 09:05:02 +00:00
|
|
|
v2 := &apeV2.ChainTarget{}
|
2024-05-06 13:26:51 +00:00
|
|
|
v2.SetTargetType(m[typ])
|
|
|
|
v2.SetName(name)
|
|
|
|
|
2024-05-28 09:05:02 +00:00
|
|
|
var ct ape.ChainTarget
|
2024-05-06 13:26:51 +00:00
|
|
|
ct.FromV2(v2)
|
|
|
|
|
|
|
|
require.Equal(t, typ, ct.TargetType)
|
|
|
|
require.Equal(t, name, ct.Name)
|
|
|
|
})
|
|
|
|
}
|