Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout setting failed in mock #1

Open
westernmonster opened this issue Jan 18, 2018 · 0 comments
Open

Timeout setting failed in mock #1

westernmonster opened this issue Jan 18, 2018 · 0 comments

Comments

@westernmonster
Copy link

import (
	"testing"
	"time"

	"github.com/tj/assert"
	mock "gopkg.in/h2non/gentleman-mock.v2"
	retry "gopkg.in/h2non/gentleman-retry.v2"
	gentleman "gopkg.in/h2non/gentleman.v2"
	"gopkg.in/h2non/gentleman.v2/plugins/timeout"
)

func TestTimeout(t *testing.T) {

	cli := gentleman.New()

	// Define the max timeout for the whole HTTP request
	cli.Use(timeout.All(timeout.Timeouts{
		Request:   10 * time.Second,
		TLS:       10 * time.Second,
		Dial:      5 * time.Second,
		KeepAlive: 30 * time.Second,
	}))

	// Register the retry plugin, using the built-in constant back off strategy
	cli.Use(retry.New(retry.ConstantBackoff))
	cli.URL("http://downloader.org/a.jpg")

	mock.New("http://downloader.org").
		Get("/*").
		Reply(201).
		BodyString("body").
		Delay(60 * time.Second)

	cli.Use(mock.Plugin)

	req := cli.Request()
	res, err := req.Send()

	assert.Nil(t, err)
	assert.True(t, res.Ok)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant