A cli application written in Go(Golang) that reads events and authorizes transactions for an account following a set of predefined rules.
-
You first need Go installed (version 1.14+ is required)
-
Install the necessary dependencies for the authorizer by executing the following command:
$ go mod tidy
- Create a file with the lines that the authorizers has to process
You can create your own or use the already created ones that are located under e2e/cases/\*/input
- Run the project and pass the file with the events you wan the authorizer to process
$ go run src/main.go < e2e/cases/account-initialize/input
In case you want to compile the authorizer, you can run the following command:
$ go build -o authorizer src/main.go
Let's pass an input file to our compiled version
$ ./authorizer < e2e/cases/account-initialize/input
The Authorizer is created using clean architecture and implementing the mediator patter in this case represented by the controller.
This way we can make the code more flexible for new business rules without creating a side effect in any other artifact.
- src
- controller
- Retrieves and parses data
- Coordinates what to do with the input data
- usecase
- Business rules that should be applied
- service
- Methods that will help to manage the model
- model
- Representation of the objects that are going to be used
- controller
Usecases are the only parts that were fully tested as it is the part that contains the business rules.
Libraries used: Gomock & testify
Gomock was used to create the corresponding mocks for the interfaces used
Testify was used for more readable assertions
- Generate the mock files that will help us out with the tests
$ make generate-mock
- Run all the tests.
$ go test ./...
# In case you want it in verbose mode
$ go test ./... -v
We can create the html coverage in case you want to check deeply which lines were covered by the tests
$ make create-test-html-coverage
The e2e tests are created using BATS(Bash Automated Testing System) since the only assertion that we need is to compare the stdout from the authorizer with the corresponding output.
Prerequisites
-
node version 14.17.0+
1.Move to the e2e directory
$ cd e2e
2.Install the dependencies
$ npm i
3.Run the unit tests
$ npm run test
Folder structure:
- e2e
- cases
- CaseFolder
- input
- output
- CaseFolder
- tests
- authorizer.bats
- cases
-
You have to create a new folder under cases with the corresponding new test name using snakecase.
-
Generate the input and output file with the content you expect to send and retrieve from the authorizer accordingly.
-
Add the new test case to the bats file
@test "Case Name" {
helper "case-name" # The name of the folder created in step 1
}