Skip to content

Commit

Permalink
use httptest server for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Feb 18, 2019
1 parent 9f04277 commit 37e1c81
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cmd/retry/examples/example_quickstart_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build example

package examples

import (
Expand All @@ -9,20 +7,33 @@ import (
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"

"github.com/kamilsk/breaker"
"github.com/kamilsk/retry/v4"
"github.com/kamilsk/retry/v4/strategy"
)

var server *httptest.Server

func TestMain(m *testing.M) {
server = httptest.NewServer(
http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) { rw.WriteHeader(http.StatusOK) }),
)
code := m.Run()
server.Close()
os.Exit(code)
}

func ExampleRetryQuickStart() {
var response *http.Response

action := func(uint) error {
var err error
response, err = http.Get("https://github.com/kamilsk/retry")
response, err = http.Get(server.URL)
return err
}

Expand All @@ -42,7 +53,7 @@ func ExampleTryQuickStart() {

action := func(uint) error {
var err error
response, err = http.Get("https://github.com/kamilsk/retry")
response, err = http.Get(server.URL)
return err
}
interrupter := breaker.MultiplexTwo(
Expand All @@ -66,7 +77,7 @@ func ExampleTryContextQuickStart() {
var response *http.Response

action := func(ctx context.Context, _ uint) error {
req, err := http.NewRequest(http.MethodGet, "https://github.com/kamilsk/retry", nil)
req, err := http.NewRequest(http.MethodGet, server.URL, nil)
if err != nil {
return err
}
Expand Down

0 comments on commit 37e1c81

Please sign in to comment.