Skip to content

orkes-io/go-httpfixture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

orkes-io/go-httpfixture

Go helpers for unit testing using dead simple HTTP fixtures.

GitHub tag (latest SemVer) GitHub Workflow Status (with event) GitHub

Usage

Installation via go get

go get github.com/orkes-io/go-httpfixture

This package provides logicless HTTP fixtures which provide a fixed response to requests, optionally asserting that the request matches an expected form.

Basic usage in a Go unit test:

package example

import (
	"testing"
	"net/http"
	"github.com/orkes-io/go-httpfixture"
)

func TestHTTP(t *testing.T) {
	s := httpfixture.NewServer(
		httpfixture.GetOK("/api/example", `{"response":"hello fixture"}`),
    )
	s.Start(t)
	defer s.Close()
	
	resp, err := http.Get(s.URL() + "/api/example")
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if resp.StatusCode != 200 {
	    t.Fatalf("expected 200 OK; got: %s", resp.StatusCode)	
    }
}

The above test starts a server which contains a single fixture, makes a GET request against the fixture, and asserts the success completed succesfully.

httpfixture serves as a terser alternative to net/http/httptest, which may be better suited to table-driven tests.

Contributing

All contributions are welcome! Please read the Contributor Covenant Code of Conduct prior to contributing.

About

Go helpers for unit testing using HTTP fixtures.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages