git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/ape/chain_test.go (about)

     1  package ape_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/ape"
     7  	"github.com/stretchr/testify/require"
     8  
     9  	apeV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape"
    10  )
    11  
    12  const (
    13  	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"}`
    14  )
    15  
    16  func TestChainData(t *testing.T) {
    17  	t.Run("raw chain", func(t *testing.T) {
    18  		var c ape.Chain
    19  
    20  		b := []byte(encoded)
    21  		c.Raw = b
    22  
    23  		v2, ok := c.ToV2().GetKind().(*apeV2.ChainRaw)
    24  		require.True(t, ok)
    25  		require.Equal(t, b, v2.Raw)
    26  	})
    27  }
    28  
    29  func TestChainMessageV2(t *testing.T) {
    30  	b := []byte(encoded)
    31  
    32  	v2Raw := &apeV2.ChainRaw{}
    33  	v2Raw.SetRaw(b)
    34  
    35  	v2 := &apeV2.Chain{}
    36  	v2.SetKind(v2Raw)
    37  
    38  	var c ape.Chain
    39  	c.ReadFromV2(v2)
    40  
    41  	require.NotNil(t, c.Raw)
    42  	require.Equal(t, b, c.Raw)
    43  }