Categorygithub.com/finarfin/go-apiclient-tester
repository
0.0.1
Repository: https://github.com/finarfin/go-apiclient-tester.git
Documentation: pkg.go.dev

# Packages

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

# README

go-apiclient-tester

GoDoc-Postman GoDoc-Tester

A simple, easy to use library to test HTTP based API clients.

Main use-case for this library is to be able to use Postman Collections for unit testing. Create requests/examples in Postman; then export as "Collection v2.1" format. It can verify that requests from your API client match to the ones in the collection and respond with the recorded response.

Example

    package awesomeclient

    import (
        "testing"
        "github.com/finarfin/go-apiclient-tester/postman"
        "github.com/finarfin/go-apiclient-tester/tester"
        "github.com/stretchr/testify/assert"
    )

    func TestUserCreateSuccess(t *testing.T) {
        tester, err := postman.NewTester("testdata/collection.json")        
        if err != nil {
            t.Fatal(err)
        }
        defer tester.Close()
        tester.Setup("user", "create_success")

        _, err = c.CreateUser("user1")
        if err != nil {
            t.Fatal(err)
        }
    }

    func TestUserCreateFailure(t *testing.T) {
        tester, err := postman.NewTester("testdata/collection.json")
        if err != nil {
            t.Fatal(err)
        }
        defer tester.Close()
        tester.Setup("user", "create_failure")

        _, err = c.CreateUser("user1")
        assert.Error(t, err)
    }

License

MIT