From cab06fb988296d7293aedf798882176e769deaa8 Mon Sep 17 00:00:00 2001 From: Anatoly Prohacky Date: Fri, 31 Mar 2023 23:30:20 +1000 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BA=D1=80=D1=8B=D1=82=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=82=D0=B5=D1=81=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- acl/aclbit.go | 7 ++--- acl/aclbit_test.go | 70 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 6 deletions(-) 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)) + + }) +}