From a84816087c7c2a7b3dc0975cbf4859d39e69c935 Mon Sep 17 00:00:00 2001 From: Anatoly Prohacky Date: Sat, 13 Aug 2022 15:47:44 +1000 Subject: [PATCH] Test acl --- .vscode/settings.json | 3 +++ Makefile | 9 +++++++++ acl/aclbit.go | 2 +- acl/aclbit_test.go | 23 +++++++++++++++++++++++ acl/testing.go | 19 +++++++++++++++++++ go.mod | 7 +++++++ go.sum | 14 ++++++++++++++ 7 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json create mode 100644 Makefile create mode 100644 acl/aclbit_test.go create mode 100644 acl/testing.go create mode 100644 go.sum diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..65e1ec0 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "makefile.extensionOutputFolder": "./.vscode" +} \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5354e5b --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +.PHONY: run +run: + go run ./main.go + +.PHONY: test +test: + go test -v -race -timeout 30s ./... + +.DEFAULT_GOAL := run diff --git a/acl/aclbit.go b/acl/aclbit.go index 279b62e..bad609e 100644 --- a/acl/aclbit.go +++ b/acl/aclbit.go @@ -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 diff --git a/acl/aclbit_test.go b/acl/aclbit_test.go new file mode 100644 index 0000000..4ee6d36 --- /dev/null +++ b/acl/aclbit_test.go @@ -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))) + } + }) +} diff --git a/acl/testing.go b/acl/testing.go new file mode 100644 index 0000000..b8cb895 --- /dev/null +++ b/acl/testing.go @@ -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 +} diff --git a/go.mod b/go.mod index b8bcba2..4220b70 100644 --- a/go.mod +++ b/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 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..b410979 --- /dev/null +++ b/go.sum @@ -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=