testdrive

command module
v0.0.0-...-2c6ef92 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 10 Imported by: 0

README

Testdrive

Testdrive


Welcome to Testdrive Go

Overview

Testdrive is a framework designed to facilitate complete end-to-end API testing. It automates scheduled API tests and notifies users via Slack about any test failures. This README provides instructions on adding new APIs for testing, setting up Slack notifications, and running Testdrive locally and deploying to AWS (Lambda with event scheduler to run every 15 mins).

Adding a New API

To add a new API for testing, follow these steps:

  1. Ensure that the API you want to test implements the Api interface, as defined in api.go.

    type Api interface {
        Name() string
        Test(client resty.Client, response chan<- Response)
    }
    
    

Here's high level overview on how to test your API (check comments api as an example for more details):

package yourapipackage

import (
    "fmt"
    "github.com/arun0009/testdrive/env"
    "github.com/arun0009/testdrive/testdrive/api"
    "github.com/go-resty/resty/v2"
    "github.com/tidwall/gjson"
)

type Api struct {
}

func (a Api) Name() string {
    return "Your ApiName"
}

// Define API endpoints and corresponding tests

func (a Api) Test(client resty.Client, apiResponse chan<- api.Response) {
    // Implement API tests
}
  1. Register your API in /testdrive/testdrive.go
    td.RegisterApi(yourapipackage.Api{})//you can inject any variables in API{}

Each API registered to test above is executed in parallel using go channels.

Setting up Slack Notifications

To receive notifications about test failures via Slack, follow these steps:

Login to Slack and create a Slack App/Channel to allow sending Slack messages on Testdrive failures.

Update env.json with your Slack Channel ID, OAuth Token (starts with xoxp) and API endpoint.

Running Testdrive Locally

To run Testdrive Lambda locally, follow these steps:

  • Install aws-sam-cli
  • Install aws-cdk npm install -g aws-cdk
  1. Create an env.json file in the root folder with the following contents:
{
    "Parameters" : {
        "API_URL": "<api-url>",
        "CHANNEL_ID": "<slack-channel>",
        "SLACK_OAUTH_TOKEN": "<slack-oauth-token>"
    }
}
  1. Use the make invoke command to run Testdrive Lambda locally.

  2. To deploy Testdrive to AWS, use make deploy. Update export values with your AWS Account details in Makefile.

  3. Console logs should display available endpoints for invocation.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL