newTestClient creates an api.Client pointing at the given httptest server URL. The server must respond to POST /api2/json/access/ticket with a valid auth response.
(t *testing.T, serverURL string)
| 167 | // newTestClient creates an api.Client pointing at the given httptest server URL. |
| 168 | // The server must respond to POST /api2/json/access/ticket with a valid auth response. |
| 169 | func newTestClient(t *testing.T, serverURL string) *api.Client { |
| 170 | t.Helper() |
| 171 | |
| 172 | cfg := &config.Config{ |
| 173 | Addr: serverURL, |
| 174 | User: "user", |
| 175 | Password: "pass", |
| 176 | Realm: "pam", |
| 177 | Insecure: true, |
| 178 | } |
| 179 | |
| 180 | client, err := api.NewClient( |
| 181 | adapters.NewConfigAdapter(cfg), |
| 182 | api.WithCache(&interfaces.NoOpCache{}), |
| 183 | ) |
| 184 | if err != nil { |
| 185 | t.Fatalf("api.NewClient: %v", err) |
| 186 | } |
| 187 | |
| 188 | return client |
| 189 | } |
| 190 | |
| 191 | // authResponse is the minimal ticket response the API client needs. |
| 192 | const authResponse = `{"data":{"ticket":"t","CSRFPreventionToken":"c","username":"user@pam"}}` |
no test coverage detected