Test acl
This commit is contained in:
parent
338b9e1999
commit
a84816087c
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"makefile.extensionOutputFolder": "./.vscode"
|
||||
}
|
9
Makefile
Normal file
9
Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
.PHONY: run
|
||||
run:
|
||||
go run ./main.go
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
go test -v -race -timeout 30s ./...
|
||||
|
||||
.DEFAULT_GOAL := run
|
@ -27,7 +27,7 @@ func veryNumBit(n NumBit) bool {
|
||||
}
|
||||
|
||||
// unite slice int to int64
|
||||
func Unite(a []AclBit) AclBit {
|
||||
func Unite(a ...AclBit) AclBit {
|
||||
var endacl AclBit
|
||||
for _, a0 := range a {
|
||||
endacl = endacl | a0
|
||||
|
23
acl/aclbit_test.go
Normal file
23
acl/aclbit_test.go
Normal file
@ -0,0 +1,23 @@
|
||||
package acl_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gitstore.ru/tolikproh/policy/acl"
|
||||
)
|
||||
|
||||
func Test_Acl(t *testing.T) {
|
||||
t.Run("Valid AclBits", func(t *testing.T) {
|
||||
for i := 0; i < 63; i++ {
|
||||
a := acl.New(acl.NumBit(i))
|
||||
assert.Equal(t, true, acl.Verify(a, acl.NumBit(i)))
|
||||
}
|
||||
})
|
||||
t.Run("NotValid AclBits", func(t *testing.T) {
|
||||
for i := -63; i == 0; i++ {
|
||||
a := acl.New(acl.NumBit(i))
|
||||
assert.NotEqual(t, true, acl.Verify(a, acl.NumBit(i)))
|
||||
}
|
||||
})
|
||||
}
|
19
acl/testing.go
Normal file
19
acl/testing.go
Normal file
@ -0,0 +1,19 @@
|
||||
package acl
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestAcl
|
||||
func TestAcl(t *testing.T) AclBit {
|
||||
t.Helper()
|
||||
|
||||
var a, b AclBit
|
||||
|
||||
for i := 0; i < 63; i++ {
|
||||
b = New(NumBit(i))
|
||||
a = Unite(a, b)
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
7
go.mod
7
go.mod
@ -1,3 +1,10 @@
|
||||
module gitstore.ru/tolikproh/policy
|
||||
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/stretchr/testify v1.8.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
14
go.sum
Normal file
14
go.sum
Normal file
@ -0,0 +1,14 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
Loading…
Reference in New Issue
Block a user