YogirajA / Totem

Contract testing for distributed systems
16 stars 4 forks source link

Totem

Don't break your consumers - Test your microservices contracts

Totem is a tool for testing the contract (message format) used by both producers and consumers; primarily for messaging used in distributed systems (like microservices). Once deployed, the Totem API will allow for automated message testing for both providers and consumers, and a GUI for manual testing by developers. Users can also view existing contracts through the GUI.

Build

CI

Deployment

Usage

  1. Deploy Totem somewhere accessible to your project's build server
  2. Create an account using the link at top right in the home screen
  3. Use the Totem UI to define the contracts you plan to test (you must be authenticated)
  4. Write tests that run on your build to hit the Totem API, using the contract ID and a sample message
  5. If the tests fail, the build should fail, since it will be incompatible with the contract definition

Features

Create Contract

The UI allows:

Test Message

Testing contracts manually via Postman

Example of running Totem locally, and hitting the API with Postman:

Testing a producer/consumer via Totem API

To test the validity of messages as a producer/consumer through the Totem API, we will need to add tests to a new/existing project, while specifying the contract ID and sample message.

{
    "Contract": {
        "type": "object",
        "properties": {
            "OrderId": {
                "$ref": "#/Guid"
            },
            "ItemName": {
                "type": "string"
            },
            "Total" : {
                "type": "integer"
            },
            "Timestamp": {
                "type": "string",
                "format": "date-time",
                "example": "2019-01-01T18:14:29Z"
            }
        }
    },
    "Guid": {
        "type": "string",
        "pattern": "^(([0-9a-f]){8}-([0-9a-f]){4}-([0-9a-f]){4}-([0-9a-f]){4}-([0-9a-f]){12})$",
        "minLength": 36,
        "maxLength": 36,
        "example": "01234567-abcd-0123-abcd-0123456789ab"
    }
}

Installation

Prerequisites

NOTE on .NET Core 3.1 upgrade

Getting Started

  1. Clone this repository
  2. Using a command prompt from the project folder run .\build to run the build script and initialize the DB
  3. From the /src/Totem folder, run npm i to install node modules
  4. Open the solution in Visual Studio, and run Totem as a service instead of with IISExpress (select Totem from the Run dropdown)
  5. Accept the SSL certificate warning if prompted

Front End Development

Most of the application's UI is built in C#, but components that require special interaction (like the contract string editor) are built in JavaScript using Vue.

Dev environment recommendations

  "editor.renderWhitespace": "all",
  "editor.tabSize": 2,
  "editor.formatOnSave": true,
  "eslint.alwaysShowStatus": true,
  "eslint.validate": [
    { "language": "vue", "autoFix": false },
    { "language": "html", "autoFix": false },
    { "language": "javascript", "autoFix": false }
  ]

Running locally

Debugging the Totem application (either through Visual Studio or from the command line, using dotnet run will automatically build and run the webpack dev server, transpiling and generating the javascript files needed by the front end. If you use the command line to debug, it will not automatically launch a browser window for you, but you can find the port it is running on in the console output: Now listening on: https://localhost:5001.

Tests

To run javascript logic tests, on the command line from the src/Totem folder, run npm run test.

To run end-to-end tests using TestCafe, on the command line from the src/Totem folder, run npm run e2e.

Contributing

Credits

Designed and built by Headspring

License

MIT © Headspring