Skip to content

canhanhan/go-apiclient-tester

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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