...

Source file src/github.com/jarcoal/httpmock/util_test.go

Documentation: github.com/jarcoal/httpmock

     1  package httpmock_test
     2  
     3  import (
     4  	"io/ioutil"
     5  	"net/http"
     6  	"os"
     7  	"testing"
     8  
     9  	"github.com/maxatome/go-testdeep/td"
    10  )
    11  
    12  func assertBody(t testing.TB, resp *http.Response, expected string) bool {
    13  	t.Helper()
    14  
    15  	require := td.Require(t)
    16  	require.NotNil(resp)
    17  
    18  	defer resp.Body.Close()
    19  
    20  	data, err := ioutil.ReadAll(resp.Body)
    21  	require.CmpNoError(err)
    22  
    23  	return td.CmpString(t, data, expected)
    24  }
    25  
    26  func tmpDir(t testing.TB) (string, func()) {
    27  	t.Helper()
    28  	dir, err := ioutil.TempDir("", "httpmock")
    29  	td.Require(t).CmpNoError(err)
    30  	return dir, func() { os.RemoveAll(dir) }
    31  }
    32  
    33  func writeFile(t testing.TB, file string, content []byte) {
    34  	t.Helper()
    35  	td.Require(t).CmpNoError(ioutil.WriteFile(file, content, 0644))
    36  }
    37  

View as plain text