Покрытие тестами

This commit is contained in:
Anatoly Prohacky 2023-03-31 23:30:20 +10:00
parent 07f03e70e1
commit cab06fb988
2 changed files with 71 additions and 6 deletions

View File

@ -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

View File

@ -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))
})
}