예제 #1
0
func testTools(code int, body string) (*httptest.Server, *Hoverfly) {

	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(code)
		w.Header().Set("Content-Type", "application/json")
		fmt.Fprintln(w, body)
	}))

	tr := &http.Transport{
		Proxy: func(req *http.Request) (*url.URL, error) {
			return url.Parse(server.URL)
		},
	}
	// creating random buckets for everyone!
	bucket := GetRandomName(10)
	metaBucket := GetRandomName(10)

	requestCache := cache.NewBoltDBCache(TestDB, bucket)
	metaCache := cache.NewBoltDBCache(TestDB, metaBucket)

	cfg := InitSettings()
	// disabling auth for testing
	cfg.AuthEnabled = false

	requestMatcher := matching.RequestMatcher{
		RequestCache:  requestCache,
		TemplateStore: matching.RequestTemplateStore{},
		Webserver:     &cfg.Webserver,
	}

	// preparing client
	dbClient := &Hoverfly{
		HTTP:           &http.Client{Transport: tr},
		RequestCache:   requestCache,
		Cfg:            cfg,
		Counter:        metrics.NewModeCounter([]string{SimulateMode, SynthesizeMode, ModifyMode, CaptureMode}),
		MetadataCache:  metaCache,
		ResponseDelays: &models.ResponseDelayList{},
		RequestMatcher: requestMatcher,
	}
	return server, dbClient
}
예제 #2
0
// GetNewHoverfly returns a configured ProxyHttpServer and DBClient
func GetNewHoverfly(cfg *Configuration, requestCache, metadataCache cache.Cache, authentication authBackend.Authentication) *Hoverfly {
	requestMatcher := matching.RequestMatcher{
		RequestCache:  requestCache,
		TemplateStore: matching.RequestTemplateStore{},
		Webserver:     &cfg.Webserver,
	}

	h := &Hoverfly{
		RequestCache:   requestCache,
		MetadataCache:  metadataCache,
		Authentication: authentication,
		HTTP:           GetDefaultHoverflyHTTPClient(cfg.TLSVerification),
		Cfg:            cfg,
		Counter:        metrics.NewModeCounter([]string{SimulateMode, SynthesizeMode, ModifyMode, CaptureMode}),
		Hooks:          make(ActionTypeHooks),
		ResponseDelays: &models.ResponseDelayList{},
		RequestMatcher: requestMatcher,
	}
	return h
}