github.com/TrueCloudLab/frostfs-api-go/v2@v2.0.0-20230228134343-196241c4e79a/container/attributes_test.go (about) 1 package container_test 2 3 import ( 4 "testing" 5 6 "github.com/TrueCloudLab/frostfs-api-go/v2/container" 7 containertest "github.com/TrueCloudLab/frostfs-api-go/v2/container/test" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestContainer_HomomorphicHashingDisabled(t *testing.T) { 12 cnr := containertest.GenerateContainer(false) 13 14 t.Run("defaults", func(t *testing.T) { 15 require.True(t, cnr.HomomorphicHashingState()) 16 }) 17 18 t.Run("disabled", func(t *testing.T) { 19 attr := container.Attribute{} 20 attr.SetKey(container.SysAttributeHomomorphicHashing) 21 attr.SetValue("NOT_true") 22 23 cnr.SetAttributes(append(cnr.GetAttributes(), attr)) 24 require.True(t, cnr.HomomorphicHashingState()) 25 26 attr.SetValue("true") 27 28 cnr.SetAttributes([]container.Attribute{attr}) 29 require.False(t, cnr.HomomorphicHashingState()) 30 }) 31 } 32 33 func TestContainer_SetHomomorphicHashingState(t *testing.T) { 34 cnr := containertest.GenerateContainer(false) 35 attrs := cnr.GetAttributes() 36 attrLen := len(attrs) 37 38 cnr.SetHomomorphicHashingState(true) 39 40 // enabling hashing should not add any new attributes 41 require.Equal(t, attrLen, len(cnr.GetAttributes())) 42 require.True(t, cnr.HomomorphicHashingState()) 43 44 cnr.SetHomomorphicHashingState(false) 45 46 // disabling hashing should add exactly one attribute 47 require.Equal(t, attrLen+1, len(cnr.GetAttributes())) 48 require.False(t, cnr.HomomorphicHashingState()) 49 50 cnr.SetHomomorphicHashingState(true) 51 52 // enabling hashing should remove 1 attribute if 53 // hashing was disabled before 54 require.Equal(t, attrLen, len(cnr.GetAttributes())) 55 require.True(t, cnr.HomomorphicHashingState()) 56 57 // hashing operations should not change any other attributes 58 require.ElementsMatch(t, attrs, cnr.GetAttributes()) 59 }