MCPcopy Index your code
hub / github.com/SpectoLabs/hoverfly / Start

Function Start

hoverctl/wrapper/hoverfly.go:164–215  ·  view source on GitHub ↗
(target *configuration.Target)

Source from the content-addressed store, hash-verified

162}
163
164func Start(target *configuration.Target) error {
165 // TODO only check port if is it localhost
166 err := checkPorts(target.AdminPort, target.ProxyPort)
167 if err != nil {
168 return err
169 }
170
171 binaryLocation, err := osext.ExecutableFolder()
172 if err != nil {
173 log.Debug(err)
174 return errors.New("Could not start Hoverfly")
175 }
176
177 _, err = runBinary(target, binaryLocation+"/hoverfly")
178 if err != nil {
179 _, err = runBinary(target, "hoverfly")
180 if err != nil {
181 return errors.New("Could not start Hoverfly")
182 }
183 }
184
185 timeout := time.After(10 * time.Second)
186 tick := time.Tick(500 * time.Millisecond)
187 statusCode := 0
188
189 for {
190 select {
191 case <-timeout:
192 if err != nil {
193 log.Debug(err)
194 }
195 return fmt.Errorf("Timed out waiting for Hoverfly to become healthy, returns status: %v", statusCode)
196 case <-tick:
197 resp, err := http.Get(fmt.Sprintf("http://localhost:%v/api/health", target.AdminPort))
198 if err == nil {
199 statusCode = resp.StatusCode
200 } else {
201 statusCode = 0
202 }
203 }
204
205 if statusCode == 200 {
206 break
207 }
208 }
209
210 if target.PACFile != "" {
211 SetPACFile(*target)
212 }
213
214 return nil
215}
216
217func Stop(target configuration.Target) error {
218 response, err := doRequest(target, "DELETE", v2ApiShutdown, "", nil)

Callers 1

start.goFile · 0.92

Calls 4

checkPortsFunction · 0.85
runBinaryFunction · 0.85
SetPACFileFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected