client: simplify test with mock-responses

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-10-23 14:20:03 +02:00
parent 1d8c8e192f
commit 47fd987af2
93 changed files with 228 additions and 1087 deletions

View File

@@ -1,10 +1,7 @@
package client
import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
"testing"
@@ -27,16 +24,9 @@ func TestSecretCreate(t *testing.T) {
if err := assertRequest(req, http.MethodPost, expectedURL); err != nil {
return nil, err
}
b, err := json.Marshal(swarm.SecretCreateResponse{
return mockJSONResponse(http.StatusCreated, nil, swarm.SecretCreateResponse{
ID: "test_secret",
})
if err != nil {
return nil, err
}
return &http.Response{
StatusCode: http.StatusCreated,
Body: io.NopCloser(bytes.NewReader(b)),
}, nil
})(req)
}))
assert.NilError(t, err)