diff options
| author | Jonathan Amsterdam <jba@google.com> | 2026-03-27 14:22:13 -0400 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2026-03-27 11:54:54 -0700 |
| commit | 58080fe0c6f1298a7578f6a9a29bf97362aabe68 (patch) | |
| tree | 7c893683577d5d5d915e47dc404eaf31cc87adb1 /internal/api | |
| parent | 0f438ccc7dbe2f891f5f97594f7b6510e490c742 (diff) | |
| download | go-x-pkgsite-58080fe0c6f1298a7578f6a9a29bf97362aabe68.tar.xz | |
internal/api: use unmarshalResponse for ServeModule
Also add a test case.
Change-Id: Iae30ecca8ebaaa412e9072de5123026ca4f78476
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/760480
kokoro-CI: kokoro <noreply+kokoro@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ethan Lee <ethanalee@google.com>
Diffstat (limited to 'internal/api')
| -rw-r--r-- | internal/api/api_test.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/internal/api/api_test.go b/internal/api/api_test.go index caa620b4..90373b66 100644 --- a/internal/api/api_test.go +++ b/internal/api/api_test.go @@ -250,7 +250,7 @@ func TestServeModule(t *testing.T) { name string url string wantStatus int - want *Module + want any }{ { name: "basic module metadata", @@ -262,6 +262,12 @@ func TestServeModule(t *testing.T) { }, }, { + name: "bad version", + url: "/v1/module/example.com?version=nope", + wantStatus: http.StatusNotFound, + want: &Error{Code: 404, Message: "could not find module for import path example.com: not found"}, + }, + { name: "module with readme", url: "/v1/module/example.com?version=v1.2.3&readme=true", wantStatus: http.StatusOK, @@ -289,11 +295,11 @@ func TestServeModule(t *testing.T) { } if test.want != nil { - var got Module - if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil { - t.Fatalf("json.Unmarshal: %v", err) + got, err := unmarshalResponse[Module](w.Body.Bytes()) + if err != nil { + t.Fatalf("unmarshaling: %v", err) } - if diff := cmp.Diff(test.want, &got); diff != "" { + if diff := cmp.Diff(test.want, got); diff != "" { t.Errorf("mismatch (-want +got):\n%s", diff) } } |
