MCPcopy
hub / github.com/SpectoLabs/hoverfly / testTools

Function testTools

core/test_tools.go:30–52  ·  view source on GitHub ↗
(code int, body string)

Source from the content-addressed store, hash-verified

28var testDB *bolt.DB
29
30func testTools(code int, body string) (*httptest.Server, *Hoverfly) {
31
32 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
33 w.WriteHeader(code)
34 w.Header().Set("Content-Type", "application/json")
35 fmt.Fprintln(w, body)
36 }))
37
38 cfg := InitSettings()
39 // disabling auth for testing
40 cfg.AuthEnabled = false
41
42 dbClient := GetNewHoverfly(cfg, cache.NewDefaultLRUCache(), nil)
43
44 tr := &http.Transport{
45 Proxy: func(req *http.Request) (*url.URL, error) {
46 return url.Parse(server.URL)
47 },
48 }
49 dbClient.HTTP = &http.Client{Transport: tr}
50
51 return server, dbClient
52}
53
54var src = rand.NewSource(time.Now().UnixNano())
55

Calls 4

NewDefaultLRUCacheFunction · 0.92
InitSettingsFunction · 0.85
GetNewHoverflyFunction · 0.85
SetMethod · 0.65