Skip to content

Instantly share code, notes, and snippets.

@leosabbir
Created June 26, 2019 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leosabbir/2be36be14032ebd9fcdfa9c2e7431264 to your computer and use it in GitHub Desktop.
Save leosabbir/2be36be14032ebd9fcdfa9c2e7431264 to your computer and use it in GitHub Desktop.
package authorization
import (
"testing"
"github.com/stretchr/testify/assert"
)
// executes becore init() method so that fileReader can be injected
var _ = func() (_ struct{}) {
fileReader = mockedFileReader
return
}()
//---------------------------------------------------------------------------------------
func mockedFileReader(filePath string) ([]byte, error) {
return []byte("{\"2\" : [1, 2, 3]}"), nil
} // mockedFileReader
//---------------------------------------------------------------------------------------
func TestAuthorize(t *testing.T) {
assert.False(t, Authorize("1", PermissionRead))
assert.True(t, Authorize("2", PermissionRead))
assert.False(t, Authorize("2", PermissionUpdate))
} // TestAuthorize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment