forked from abdullahselek/go-here
/
test_util.go
40 lines (37 loc) · 867 Bytes
/
test_util.go
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
37
38
39
40
package here
import (
"context"
"crypto/tls"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
"os"
)
func testingHTTPClient(handler http.Handler) (*http.Client, func()) {
s := httptest.NewTLSServer(handler)
cli := &http.Client{
Transport: &http.Transport{
DialContext: func(_ context.Context, network, _ string) (net.Conn, error) {
return net.Dial(network, s.Listener.Addr().String())
},
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
}
return cli, s.Close
}
func readJSONFile(fileName string) []byte {
// Open our jsonFile
jsonFile, err := os.Open(fileName)
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
}
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
return byteValue
}