()
| 77 | } |
| 78 | |
| 79 | func (c Config) CreateUnstarted() *TestProxy { |
| 80 | waitTime := 3 * time.Second |
| 81 | if c.WaitTime > 0 { |
| 82 | waitTime = c.WaitTime |
| 83 | } |
| 84 | |
| 85 | endpointRegistry := routing.NewEndpointRegistry(routing.RegistryOptions{}) |
| 86 | tl := loggingtest.New() |
| 87 | var dc *testdataclient.Client |
| 88 | |
| 89 | if len(c.RoutingOptions.DataClients) == 0 { |
| 90 | dc = testdataclient.New(c.Routes) |
| 91 | c.RoutingOptions.DataClients = []routing.DataClient{dc} |
| 92 | } |
| 93 | |
| 94 | c.RoutingOptions.Log = tl |
| 95 | c.RoutingOptions.PostProcessors = append(c.RoutingOptions.PostProcessors, loadbalancer.NewAlgorithmProvider(), endpointRegistry) |
| 96 | |
| 97 | rt := routing.New(c.RoutingOptions) |
| 98 | c.ProxyParams.Routing = rt |
| 99 | c.ProxyParams.EndpointRegistry = endpointRegistry |
| 100 | |
| 101 | pr := proxy.WithParams(c.ProxyParams) |
| 102 | |
| 103 | var tsp *httptest.Server |
| 104 | |
| 105 | if len(c.Certificates) > 0 { |
| 106 | tsp = httptest.NewUnstartedServer(pr) |
| 107 | tsp.TLS = &tls.Config{Certificates: c.Certificates} |
| 108 | } else { |
| 109 | tsp = httptest.NewUnstartedServer(pr) |
| 110 | } |
| 111 | |
| 112 | if err := tl.WaitFor("route settings applied", waitTime); err != nil { |
| 113 | panic(err) |
| 114 | } |
| 115 | |
| 116 | _, port, _ := net.SplitHostPort(tsp.Listener.Addr().String()) |
| 117 | |
| 118 | return &TestProxy{ |
| 119 | URL: tsp.URL, |
| 120 | Port: port, |
| 121 | Log: tl, |
| 122 | dc: dc, |
| 123 | routing: rt, |
| 124 | proxy: pr, |
| 125 | server: tsp, |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | func (p *TestProxy) Start() { |
| 130 | if p.server.TLS != nil { |
no test coverage detected