diff --git a/acl/aclbit.go b/acl/aclbit.go index 0faa7ea..52fb581 100644 --- a/acl/aclbit.go +++ b/acl/aclbit.go @@ -13,12 +13,11 @@ const ( ) // New AclBit -func New(n ...NumBit) AclBit { - var i64 AclBit +func New(n ...NumBit) (a AclBit) { - i64.SetTrue(n...) + a.SetTrue(n...) - return i64 + return a } // unite slice int to int64 diff --git a/acl/aclbit_test.go b/acl/aclbit_test.go index 80dc853..82b0ccc 100644 --- a/acl/aclbit_test.go +++ b/acl/aclbit_test.go @@ -7,8 +7,8 @@ import ( "gitstore.ru/tolikproh/policy/acl" ) -func Test_Acl(t *testing.T) { - t.Run("Valid AclBits", func(t *testing.T) { +func Test_Verify(t *testing.T) { + t.Run("Verify AclBits", func(t *testing.T) { for i := 0; i < 63; i++ { a := acl.New(acl.NumBit(i)) assert.Equal(t, true, a.Verify(acl.NumBit(i))) @@ -21,3 +21,69 @@ func Test_Acl(t *testing.T) { } }) } + +func Test_VerifyOr(t *testing.T) { + + t.Run("VarifyOr AclBits", func(t *testing.T) { + a := acl.AllBit + for i := 0; i < 63; i++ { + assert.Equal(t, true, a.VerifyOr(acl.NumBit(i))) + } + }) + t.Run("NotValid AclBits", func(t *testing.T) { + a := acl.AllBit + for i := -63; i == 0; i++ { + assert.NotEqual(t, true, a.VerifyOr(acl.NumBit(i))) + } + }) +} + +func Test_VerifyAnd(t *testing.T) { + + t.Run("VarifyOr AclBits", func(t *testing.T) { + a := acl.AllBit + for i := 0; i < 63; i++ { + assert.Equal(t, true, a.VerifyAnd(acl.NumBit(i))) + } + }) + t.Run("NotValid AclBits", func(t *testing.T) { + a := acl.AllBit + for i := -63; i == 0; i++ { + assert.NotEqual(t, true, a.VerifyAnd(acl.NumBit(i))) + } + }) +} + +func Test_VerifyMask(t *testing.T) { + a := acl.AllBit + t.Run("VarifyMask AclBits", func(t *testing.T) { + for i := 0; i < 63; i++ { + assert.Equal(t, true, a.VerifyMask(acl.New(acl.NumBit(i)))) + } + }) + + a = 0 + t.Run("NotValid AclBits", func(t *testing.T) { + for i := 0; i < 63; i++ { + assert.NotEqual(t, true, a.VerifyMask(acl.New(acl.NumBit(i)))) + } + }) +} + +func Test_Unite(t *testing.T) { + a := acl.New(0, 1, 6, 9, 10) + b := acl.New(3, 7, 16, 26, 35) + c := acl.New(42, 46, 54, 59, 61) + equal := acl.New(0, 1, 6, 9, 10, 3, 7, 16, 26, 35, 42, 46, 54, 59, 61) + notEqual := acl.New(2, 4, 5) + + t.Run("Unite AclBits", func(t *testing.T) { + for i := 0; i < 63; i++ { + assert.Equal(t, equal, acl.Unite(a, b, c)) + } + }) + t.Run("NotUnite AclBits", func(t *testing.T) { + assert.NotEqual(t, notEqual, acl.Unite(a, b, c)) + + }) +}