| 76 | } |
| 77 | |
| 78 | func (c *Client) ResetState() error { |
| 79 | req, err := http.NewRequest("POST", c.endpoint+"/reset", http.NoBody) |
| 80 | if err != nil { |
| 81 | return fmt.Errorf("failed to make reset request: %w", err) |
| 82 | } |
| 83 | resp, err := c.httpClient.Do(req) // #nosec G704 -- toxiproxy endpoint is controlled test infrastructure. |
| 84 | if err != nil { |
| 85 | return fmt.Errorf("failed to http post reset: %w", err) |
| 86 | } |
| 87 | defer resp.Body.Close() |
| 88 | |
| 89 | if resp.StatusCode != 204 { |
| 90 | body, _ := io.ReadAll(resp.Body) |
| 91 | return fmt.Errorf("error resetting proxies: %s %s", resp.Status, body) |
| 92 | } |
| 93 | |
| 94 | return nil |
| 95 | } |