GithubHelp home page GithubHelp logo

authorizer's Introduction

Authorizer

Coverage

A cli application written in Go(Golang) that reads events and authorizes transactions for an account following a set of predefined rules.

Contents

Getting started

  1. You first need Go installed (version 1.14+ is required)

  2. Install the necessary dependencies for the authorizer by executing the following command:

  $ go mod tidy
  1. 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
  1. 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

Documentation

The Authorizer is created using clean architecture and implementing the mediator patter in this case represented by the controller.

Why Clean architecture?

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

Unit tests

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

  1. Generate the mock files that will help us out with the tests
  $ make generate-mock
  1. 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

e2e Tests

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

How to add a new e2e test

Folder structure:

  • e2e
    • cases
      • CaseFolder
        • input
        • output
    • tests
      • authorizer.bats
  1. You have to create a new folder under cases with the corresponding new test name using snakecase.

  2. Generate the input and output file with the content you expect to send and retrieve from the authorizer accordingly.

  3. Add the new test case to the bats file

@test "Case Name" {
  helper "case-name" # The name of the folder created in step 1
}

authorizer's People

Contributors

awize-acs avatar mickambar19 avatar

Stargazers

 avatar

Watchers

 avatar Marco Robles  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.