MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / newTestClient

Function newTestClient

internal/cli/cli_helpers_test.go:169–189  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
169func 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.
192const authResponse = `{"data":{"ticket":"t","CSRFPreventionToken":"c","username":"user@pam"}}`

Calls 3

NewClientFunction · 0.92
NewConfigAdapterFunction · 0.92
WithCacheFunction · 0.92

Tested by

no test coverage detected