Categorygithub.com/bastianrob/go-restify
modulepackage
0.1.2
Repository: https://github.com/bastianrob/go-restify.git
Documentation: pkg.go.dev

# README

go-restify

This package helps you automate API testing

Limitation

Only works for JSON API

Dependencies

"github.com/bastianrob/go-valuator"
"github.com/buger/jsonparser"

Example

Setting up test scenario

buffer := bytes.Buffer{}
scenario.New().Set().
    Name("Scenario One").
    Environment("Local").
    Description("").
    AddCase(restify.TestCase{
        Order:       1,
        Name:        "Setup Auth",
        Description: "Auth to firebase",
        Request: restify.Request{
            URL:    "https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key={YOUR_FIREBASE_KEY}",
            Method: "POST",
            Payload: json.RawMessage(`{
                "email": "[email protected]",
                "password": "your.password",
                "returnSecureToken": true
            }`),
        },
        Expect: restify.Expect{
            StatusCode: 200,
            Evaluate: []restify.Expression{{
                Prop:        "idToken",
                Operator:    "!=",
                Value:       "",
                Description: "ID Token must be returned from firebase",
            }},
        },
        Pipeline: restify.Pipeline{
            Cache:     true,
            CacheAs:   "auth",
            OnFailure: onfailure.Exit,
        },
    }).
    AddCase(restify.TestCase{
        Order:       2,
        Name:        "Get List",
        Description: "Get a list of resource that returns {data: [{resource1, resource2}]}",
        Request: restify.Request{
            URL:    "http://localhost:3000/resources",
            Method: "GET",
            Headers: map[string]string{
                "Authorization": "Bearer {auth.idToken}",
            },
            Payload: nil,
        },
        Expect: restify.Expect{
            StatusCode:       200,
            Evaluate: []restify.Expression{{
                Object:      "data.[0]",
                Prop:        "id",
                Operator:    "!=",
                Value:       "",
                Description: "Returned data is not empty",
            }},
        },
        Pipeline: restify.Pipeline{
            Cache:     true,
            CacheAs:   "R1",
            OnFailure: onfailure.Exit,
        },
    }).
    AddCase(restify.TestCase{
        Order:       3,
        Name:        "Get One",
        Description: "Get one resource from previous case",
        Request: restify.Request{
            URL:    "http://localhost:3000/resources/{R1.data.[0].id}",
            Method: "GET",
            Headers: map[string]string{
                "Authorization": "Bearer {auth.idToken}",
            },
            Payload: nil,
        },
        Expect: restify.Expect{
            StatusCode:       200,
            Evaluate: []restify.Expression{{
                Object:      "data",
                Prop:        "id",
                Operator:    "!=",
                Value:       "",
                Description: "Returned data is not empty",
            }},
        },
        Pipeline: restify.Pipeline{
            Cache:     true,
            CacheAs:   "R2",
            OnFailure: onfailure.Exit,
        },
    }).End().
    Run(&buffer)

# Packages

No description provided by the author
No description provided by the author

# Functions

NewTestResult from scenario.

# Structs

Expect response expectation.
Expression rule of expected response.
Pipeline test pipeline as what to do with the response object.
Request test object.
TestCase struct.
TestResult object, all properties must be flat (not nested / denormalized)Hopefully de-normalizing the structure can make analytic easierGenerally immutable, so we don't need ID and just let DB auto gen for us.

# Interfaces

Scenario is the biggest scope of a testCan have multiple test cases.
ScenarioGetter access to get scenario properties.
ScenarioSetter access to set scenario properties.