aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/api/api_test.go16
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)
}
}