-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.go
50 lines (39 loc) · 966 Bytes
/
server_test.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
41
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"log/slog"
"net/http"
"net/http/httptest"
"os"
"testing"
)
func newTestServer(t *testing.T, client *http.Client) (*httptest.Server, func()) {
t.Helper()
cfg, err := newConfig("address is not used when running tests")
if err != nil {
t.Fatal(err)
}
url, ok := os.LookupEnv("ALCHEMY")
if !ok {
t.Fatal("env variable ALCHEMY must be set")
}
// we only use one endpoint in these tests in order to
// simplify testing and recording of the requests.
cfg.Gateways = map[string]string{
"Alchemy": url,
}
cfg.GatewaysMinimumClients = 1
appOpts := newOptions(cfg, slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelWarn, AddSource: true})))
if client != nil {
appOpts.httpClient = client
}
app, cleanup, err := newApp(context.Background(), appOpts)
if err != nil {
t.Fatal(err)
}
ts := httptest.NewServer(app.handler())
return ts, func() {
cleanup()
ts.Close()
}
}