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
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
encoded = `{"ID":"","Rules":[{"Status":"Allow","Actions":{"Inverted":false,"Names":["GetObject"]},"Resources":{"Inverted":false,"Names":["native:object/*"]},"Any":false,"Condition":[{"Op":"StringEquals","Object":"Resource","Key":"Department","Value":"HR"}]}],"MatchType":"DenyPriority"}`
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestChainData(t *testing.T) {
|
|
|
|
t.Run("raw chain", func(t *testing.T) {
|
2024-05-28 09:05:02 +00:00
|
|
|
var c ape.Chain
|
2024-05-06 13:26:51 +00:00
|
|
|
|
|
|
|
b := []byte(encoded)
|
|
|
|
c.Raw = b
|
|
|
|
|
2024-05-28 09:05:02 +00:00
|
|
|
v2, ok := c.ToV2().GetKind().(*apeV2.ChainRaw)
|
2024-05-06 13:26:51 +00:00
|
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, b, v2.Raw)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestChainMessageV2(t *testing.T) {
|
|
|
|
b := []byte(encoded)
|
|
|
|
|
2024-05-28 09:05:02 +00:00
|
|
|
v2Raw := &apeV2.ChainRaw{}
|
2024-05-06 13:26:51 +00:00
|
|
|
v2Raw.SetRaw(b)
|
|
|
|
|
2024-05-28 09:05:02 +00:00
|
|
|
v2 := &apeV2.Chain{}
|
2024-05-06 13:26:51 +00:00
|
|
|
v2.SetKind(v2Raw)
|
|
|
|
|
2024-05-28 09:05:02 +00:00
|
|
|
var c ape.Chain
|
2024-05-06 13:26:51 +00:00
|
|
|
c.ReadFromV2(v2)
|
|
|
|
|
|
|
|
require.NotNil(t, c.Raw)
|
|
|
|
require.Equal(t, b, c.Raw)
|
|
|
|
}
|