-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_test.go
36 lines (30 loc) · 885 Bytes
/
demo_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
package pluginDemo_test
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/LeslieRan/pluginDemo"
)
func TestDemo(t *testing.T) {
cfg := pluginDemo.CreateConfig()
cfg.Info = "Hello"
ctx := context.Background()
next := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {})
handler, err := pluginDemo.New(ctx, next, cfg, "demo-plugin")
if err != nil {
t.Fatalf("new plugin:%s\n", err.Error())
}
recorder := httptest.NewRecorder()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://localhost", nil)
if err != nil {
t.Fatalf("new http request:%s\n", err.Error())
}
// client := http.DefaultClient
// resp, err := client.Do(req)
// if err != nil {
// t.Fatalf("send http request:%s\n", err.Error())
// }
// t.Logf("response: %d and %s\n", resp.StatusCode, resp.Status)
handler.ServeHTTP(recorder, req)
}