Skip to content

Commit

Permalink
Testing has permission.
Browse files Browse the repository at this point in the history
  • Loading branch information
João Silva committed Nov 15, 2017
1 parent b6691eb commit d177412
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
52 changes: 30 additions & 22 deletions permissions_test.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
package go_pex

import "testing"
import (
"testing"
"strconv"
"strings"
)

type StructA struct {
Slice []int
Pointer *StructB
SlicePointer []*StructB
}

type StructB struct {
Text string
}
func TestHasPermission(t *testing.T) {
permissionTag := strings.Join(
[]string{
strconv.Itoa(PermissionNone),
strconv.Itoa(PermissionRead),
strconv.Itoa(PermissionWrite),
strconv.Itoa(PermissionReadWrite),
}, "")

func TestGetReflectValue(t *testing.T) {
tables := []struct {
x int
y int
n int
tag string
userType uint
action uint
result bool
}{
{1, 1, 2},
{1, 2, 3},
{2, 2, 4},
{5, 2, 7},
{permissionTag, 0, ActionRead, false},
{permissionTag, 0, ActionWrite, false},
{permissionTag, 1, ActionRead, true},
{permissionTag, 1, ActionWrite, false},
{permissionTag, 2, ActionRead, false},
{permissionTag, 2, ActionWrite, true},
{permissionTag, 3, ActionRead, true},
{permissionTag, 3, ActionWrite, true},
}

for _, table := range tables {
total := Sum(table.x, table.y)
if total != table.n {
t.Errorf("Sum of (%d+%d) was incorrect, got: %d, want: %d.", table.x, table.y, total, table.n)
hasPermission := HasPermission(table.tag, table.userType, table.action)
if hasPermission != table.result {
t.Errorf("Has permission (tag = %s, userType = %d, action = %d) was incorrect, got: %t, want: %t.",
table.tag, table.userType, table.action, hasPermission, table.result)
}
}
}
}
9 changes: 2 additions & 7 deletions tmp.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package go_pex

import (
"reflect"
"encoding/json"
"strings"
"time"
)

/*
// CleanStruct removes the fields that the user can't read / write
func CleanStruct(obj interface{}, userType uint, action uint) {
// Remove fields without permission to change
Expand Down Expand Up @@ -187,3 +181,4 @@ func RemoveFields(obj interface{}, userType uint, action uint) interface{} {
return resultObject
}
*/

0 comments on commit d177412

Please sign in to comment.