Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/connectors/microcks_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func (c *microcksClient) DownloadArtifact(artifactURL string, mainArtifact bool,
// Dump response if verbose required.
config.DumpResponseIfRequired("Microcks for uploading artifact", resp, true)

respBody, err := io.ReadAll(req.Body)
respBody, err := io.ReadAll(resp.Body)
if err != nil {
panic(err.Error())
}
Expand Down
43 changes: 43 additions & 0 deletions pkg/connectors/microcks_client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package connectors

import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)

func TestDownloadArtifactReturnsResponseBody(t *testing.T) {
const expectedBody = "artifact downloaded"

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/artifact/download" {
t.Fatalf("unexpected path: %s", r.URL.Path)
}
if r.Method != http.MethodPost {
t.Fatalf("unexpected method: %s", r.Method)
}
if err := r.ParseMultipartForm(1024); err != nil {
t.Fatalf("failed to parse multipart form: %v", err)
}
if got := r.FormValue("url"); got != "https://example.com/openapi.yaml" {
t.Fatalf("unexpected artifact url: %s", got)
}
if got := r.FormValue("mainArtifact"); got != "true" {
t.Fatalf("unexpected mainArtifact value: %s", got)
}
w.WriteHeader(http.StatusCreated)
_, _ = w.Write([]byte(expectedBody))
}))
defer server.Close()

client := NewMicrocksClient(server.URL)

msg, err := client.DownloadArtifact("https://example.com/openapi.yaml", true, "")
if err != nil {
t.Fatalf("DownloadArtifact returned error: %v", err)
}
if strings.TrimSpace(msg) != expectedBody {
t.Fatalf("expected response body %q, got %q", expectedBody, msg)
}
}
Loading