requesttest

package module
v0.0.0-...-372365b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2019 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

requesttest

Go Report Card Godoc

Simple HTTP test library.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Echo

func Echo() (string, func())

Echo a request's method and payload in JSON.

Example
package main

import (
	"fmt"

	"github.com/hoanhan101/request"
	"github.com/hoanhan101/requesttest"
)

// Response describes a response from requesttest.Echo().
type Response struct {
	Method  string      `json:"method"`
	Payload interface{} `json:"payload"`
}

func main() {
	url, closer := requesttest.Echo()
	defer closer()

	r := new(Response)

	err := request.GetJSON(
		&request.Options{
			URL:     url,
			Payload: map[string]string{"k1": "v1"},
		},
		r,
	)
	if err != nil {
		fmt.Println(err)
	}

	fmt.Printf("%+v\n", r)
}
Output:
&{Method:GET Payload:k1=v1}

func Mock

func Mock(response interface{}) (string, func())

Mock a JSON response.

Example
package main

import (
	"fmt"

	"github.com/hoanhan101/request"
	"github.com/hoanhan101/requesttest"
)

// Response describes a response from requesttest.Echo().
type Response struct {
	Method  string      `json:"method"`
	Payload interface{} `json:"payload"`
}

func main() {
	url, closer := requesttest.Mock(`{"method":"GET","payload":{"k1":"k2"}}`)
	defer closer()

	r := new(Response)

	err := request.GetJSON(
		&request.Options{
			URL: url,
		},
		r,
	)
	if err != nil {
		fmt.Println(err)
	}

	fmt.Printf("%+v\n", r)
}
Output:
&{Method:GET Payload:map[k1:k2]}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL