-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add unit tests for authZ (#1359)
Signed-off-by: Sidhant Kohli <[email protected]>
- Loading branch information
Showing
7 changed files
with
457 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package authz | ||
|
||
type options struct { | ||
policyMapPath string | ||
rbacPropertiesPath string | ||
} | ||
|
||
// Option is the interface to apply options. | ||
type Option func(*options) | ||
|
||
func DefaultOptions() *options { | ||
return &options{ | ||
policyMapPath: policyMapPath, | ||
rbacPropertiesPath: rbacPropertiesPath, | ||
} | ||
} | ||
|
||
// WithPolicyMap sets the policy map path to be used for the RBAC enforcer | ||
func WithPolicyMap(path string) Option { | ||
return func(opts *options) { | ||
opts.policyMapPath = path | ||
} | ||
} | ||
|
||
// WithPropertyFile sets the property file path to be used for the RBAC enforcer | ||
func WithPropertyFile(path string) Option { | ||
return func(opts *options) { | ||
opts.rbacPropertiesPath = path | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package authz | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestWithPolicyMap is a test implementation of the WithPolicyMap function. | ||
// It tests that the policy map path is set correctly. | ||
func TestWithPolicyMap(t *testing.T) { | ||
var ( | ||
testPolicyMapPath = "test-policy-map-path" | ||
opts = &options{ | ||
policyMapPath: policyMapPath, | ||
} | ||
) | ||
WithPolicyMap(testPolicyMapPath)(opts) | ||
assert.Equal(t, testPolicyMapPath, opts.policyMapPath) | ||
} | ||
|
||
// TestWithPropertyFile is a test implementation of the WithPropertyFile function. | ||
// It tests that the property file path is set correctly. | ||
func TestWithPropertyFile(t *testing.T) { | ||
var ( | ||
testPropertyFilePath = "test-property-file-path" | ||
opts = &options{ | ||
rbacPropertiesPath: rbacPropertiesPath, | ||
} | ||
) | ||
WithPropertyFile(testPropertyFilePath)(opts) | ||
assert.Equal(t, testPropertyFilePath, opts.rbacPropertiesPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.