Skip to content
Open
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
6 changes: 6 additions & 0 deletions internal/server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ func (a *API) Complete() {

// ServeHTTP handles requests to the server
func (a *API) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
// Updaters can tolerate unavailable read APIs, but an empty success response is malformed.
http.Error(w, "read API is not implemented by the local CLI", http.StatusNotImplemented)
return
}

data, err := io.ReadAll(r.Body)
if err != nil {
err = fmt.Errorf("failed to read body: %w", err)
Expand Down
26 changes: 26 additions & 0 deletions internal/server/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ func TestAPI_ServeHTTP(t *testing.T) {
})
}

func TestAPI_UnsupportedGet(t *testing.T) {
for _, path := range []string{
"/update_jobs/cli/blocked_versions?package-manager=go_modules",
"/update_jobs/cli/unknown_read",
} {
t.Run(path, func(t *testing.T) {
var stdout bytes.Buffer
api := &API{writer: &stdout}
request := httptest.NewRequest(http.MethodGet, path, nil)
response := httptest.NewRecorder()

api.ServeHTTP(response, request)

if response.Code != http.StatusNotImplemented {
t.Errorf("expected status %d, got %d", http.StatusNotImplemented, response.Code)
}
if len(api.Errors) != 0 || len(api.Actual.Output) != 0 || stdout.Len() != 0 {
t.Errorf("unsupported read recorded as an event: errors=%v outputs=%v stdout=%q", api.Errors, api.Actual.Output, stdout.String())
}
if api.cursor != 0 {
t.Errorf("unsupported read consumed an expectation: cursor=%d", api.cursor)
}
})
}
}

type Wrapper[T any] struct {
Data T `json:"data"`
}
Expand Down
Loading