File: util_test.go

package info (click to toggle)
golang-github-jarcoal-httpmock 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 332 kB
  • sloc: makefile: 2
file content (36 lines) | stat: -rw-r--r-- 726 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package httpmock_test

import (
	"io/ioutil" //nolint: staticcheck
	"net/http"
	"os"
	"testing"

	"github.com/maxatome/go-testdeep/td"
)

func assertBody(t testing.TB, resp *http.Response, expected string) bool {
	t.Helper()

	require := td.Require(t)
	require.NotNil(resp)

	defer resp.Body.Close()

	data, err := ioutil.ReadAll(resp.Body)
	require.CmpNoError(err)

	return td.CmpString(t, data, expected)
}

func tmpDir(t testing.TB) (string, func()) {
	t.Helper()
	dir, err := ioutil.TempDir("", "httpmock")
	td.Require(t).CmpNoError(err)
	return dir, func() { os.RemoveAll(dir) }
}

func writeFile(t testing.TB, file string, content []byte) {
	t.Helper()
	td.Require(t).CmpNoError(ioutil.WriteFile(file, content, 0644))
}