generated from bool64/go-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
example_test.go
52 lines (42 loc) · 1.1 KB
/
example_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
51
52
package httpsteps_test
import (
"fmt"
"io"
"net/http"
"net/http/httptest"
"github.com/cucumber/godog"
"github.com/godogx/httpsteps"
)
func ExampleNewLocalClient() {
external := httpsteps.NewExternalServer()
templateService := external.Add("template-service")
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
req, _ := http.NewRequest(http.MethodGet, templateService+"/template/hello", nil)
resp, _ := http.DefaultTransport.RoundTrip(req)
tpl, _ := io.ReadAll(resp.Body)
_ = resp.Body.Close()
_, _ = w.Write([]byte(fmt.Sprintf(string(tpl), r.URL.Query().Get("name"))))
})
srv := httptest.NewServer(h)
defer srv.Close()
local := httpsteps.NewLocalClient(srv.URL)
suite := godog.TestSuite{
ScenarioInitializer: func(s *godog.ScenarioContext) {
local.RegisterSteps(s)
external.RegisterSteps(s)
},
Options: &godog.Options{
Format: "pretty",
Strict: true,
Paths: []string{"_testdata/Example.feature"},
Output: io.Discard,
},
}
if suite.Run() != 0 {
fmt.Println("test failed")
} else {
fmt.Println("test passed")
}
// Output:
// test passed
}