Skip to content

Commit f6599aa

Browse files
authored
Refactor: split test code into files (#47)
1 parent 42995bd commit f6599aa

File tree

5 files changed

+348
-318
lines changed

5 files changed

+348
-318
lines changed

e2e_test/client/client.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package client
2+
3+
import (
4+
"crypto/tls"
5+
"crypto/x509"
6+
"fmt"
7+
"io/ioutil"
8+
"net/http"
9+
)
10+
11+
var certPool = x509.NewCertPool()
12+
13+
func init() {
14+
data, err := ioutil.ReadFile("testdata/ca.pem")
15+
if err != nil {
16+
panic(err)
17+
}
18+
if !certPool.AppendCertsFromPEM(data) {
19+
panic("could not append certificate data")
20+
}
21+
}
22+
23+
func Get(url string) (int, string, error) {
24+
client := http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{RootCAs: certPool}}}
25+
resp, err := client.Get(url)
26+
if err != nil {
27+
return 0, "", fmt.Errorf("could not send a request: %w", err)
28+
}
29+
defer resp.Body.Close()
30+
b, err := ioutil.ReadAll(resp.Body)
31+
if err != nil {
32+
return resp.StatusCode, "", fmt.Errorf("could not read response body: %w", err)
33+
}
34+
return resp.StatusCode, string(b), nil
35+
}

0 commit comments

Comments
 (0)