Skip to content

Alex-PK/go-mochte

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mochte

An HTTP server mocking framework that allows you to verify assertions on the routes and possibly check the order in which the routes are called.

Status

Under heavy development.

APIs can change, documentation is bare minimal. Keeping this in mind, suggestions and contributions are welcome. :)

Example

You just need to create a server, add some routes with their own assertions, then run the server and defer its closing.

You then use a normal http.Client to connect to the exposed URL and the server will verify the assertions.

import "http://github.com/alex-pk/mochte"

func TestBasics(t *testing.T) {
	defer mochte.NewServerOn(t, ":49999").
		ListenOrdered().
		Add(mochte.NewRoute().
		Method(GET).
		Path("/").
		Status(200).
		Body("OK...").
		AssertIsCalledAtLeastNTimes(1),
	).Run().Close()

	res, err := http.Get("http://localhost:49999" + "/")
	if err != nil {
		t.Error(err)
	}

	t.Logf("Result: %#v", res)
}

About

An HTTP server mocking library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages