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
9 changes: 5 additions & 4 deletions internal/maven/maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ type searchResponseBody struct {
}

type searchDoc struct {
ID string `json:"id"`
GroupID string `json:"g"`
ArtifactID string `json:"a"`
Version string `json:"latestVersion"`
ID string `json:"id"`
GroupID string `json:"g"`
ArtifactID string `json:"a"`
// core=gav returns the version in "v"; "latestVersion" only exists on the non-gav aggregated core.
Version string `json:"v"`
Timestamp int64 `json:"timestamp"`
VersionCount int `json:"versionCount"`
}
Expand Down
35 changes: 35 additions & 0 deletions internal/maven/maven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
"reflect"
"testing"

"github.com/git-pkgs/registries/internal/core"
Expand Down Expand Up @@ -141,6 +142,40 @@ func TestFetchVersions(t *testing.T) {
}
}

func TestFetchVersionsParsesRealSolrGavShape(t *testing.T) {
const body = `{"responseHeader":{"status":0},"response":{"numFound":3,"start":0,"docs":[
{"id":"org.slf4j:slf4j-api:2.0.17","g":"org.slf4j","a":"slf4j-api","v":"2.0.17","p":"jar","timestamp":1740501794416},
{"id":"org.slf4j:slf4j-api:2.0.16","g":"org.slf4j","a":"slf4j-api","v":"2.0.16","p":"jar","timestamp":1725000000000},
{"id":"org.slf4j:slf4j-api:1.7.36","g":"org.slf4j","a":"slf4j-api","v":"1.7.36","p":"jar","timestamp":1645000000000}
]}}`

mux := http.NewServeMux()
mux.HandleFunc("/solrsearch/select", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
})
server := httptest.NewServer(mux)
defer server.Close()

reg := New(server.URL, core.DefaultClient())
reg.searchURL = server.URL

versions, err := reg.FetchVersions(context.Background(), "org.slf4j:slf4j-api")
if err != nil {
t.Fatalf("FetchVersions failed: %v", err)
}
got := make([]string, len(versions))
for i, v := range versions {
if v.Number == "" {
t.Fatalf("version %d has empty Number - searchDoc is not reading the Solr \"v\" field", i)
}
got[i] = v.Number
}
want := []string{"2.0.17", "2.0.16", "1.7.36"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("versions = %v, want %v", got, want)
}
}

func TestFetchVersionsFallback(t *testing.T) {
mux := http.NewServeMux()

Expand Down