From 834db962958652502aba88362dbe91df2ee618ee Mon Sep 17 00:00:00 2001 From: Ophestra Date: Tue, 15 Sep 2026 00:06:21 +0900 Subject: cmd/mbf: rename pkgsite This name is less ambiguous than pkgserver. Signed-off-by: Ophestra --- cmd/mbf/internal/pkgserver/api_test.go | 111 --------------------------------- 1 file changed, 111 deletions(-) delete mode 100644 cmd/mbf/internal/pkgserver/api_test.go (limited to 'cmd/mbf/internal/pkgserver/api_test.go') diff --git a/cmd/mbf/internal/pkgserver/api_test.go b/cmd/mbf/internal/pkgserver/api_test.go deleted file mode 100644 index 1552fec9..00000000 --- a/cmd/mbf/internal/pkgserver/api_test.go +++ /dev/null @@ -1,111 +0,0 @@ -package pkgserver - -import ( - "net/http" - "net/http/httptest" - "strconv" - "testing" - - "hakurei.app/internal/info" - "hakurei.app/internal/rosa" -) - -// prefix is prepended to every API path. -const prefix = "/api/" + apiVersion + "/" - -func TestAPIInfo(t *testing.T) { - t.Parallel() - - w := httptest.NewRecorder() - handleInfo(w, httptest.NewRequestWithContext( - t.Context(), - http.MethodGet, - prefix+"info", - nil, - )) - - resp := w.Result() - checkStatus(t, resp, http.StatusOK) - checkAPIHeader(t, w.Header()) - - checkPayload(t, resp, struct { - Count int `json:"count"` - HakureiVersion string `json:"hakurei_version"` - }{len(rosa.Collect()), info.Version()}) -} - -func TestAPIGet(t *testing.T) { - t.Parallel() - const target = prefix + "get" - - index := newIndex(t) - newRequest := func(suffix string) *httptest.ResponseRecorder { - w := httptest.NewRecorder() - index.handleGet(w, httptest.NewRequestWithContext( - t.Context(), - http.MethodGet, - target+suffix, - nil, - )) - return w - } - - checkValidate := func(t *testing.T, suffix string, vmin, vmax int, wantErr string) { - t.Run("invalid", func(t *testing.T) { - t.Parallel() - - w := newRequest("?" + suffix + "=invalid") - resp := w.Result() - checkError(t, resp, wantErr, http.StatusBadRequest) - }) - - t.Run("min", func(t *testing.T) { - t.Parallel() - - w := newRequest("?" + suffix + "=" + strconv.Itoa(vmin-1)) - resp := w.Result() - checkError(t, resp, wantErr, http.StatusBadRequest) - - w = newRequest("?" + suffix + "=" + strconv.Itoa(vmin)) - resp = w.Result() - checkStatus(t, resp, http.StatusOK) - }) - - t.Run("max", func(t *testing.T) { - t.Parallel() - - w := newRequest("?" + suffix + "=" + strconv.Itoa(vmax+1)) - resp := w.Result() - checkError(t, resp, wantErr, http.StatusBadRequest) - - w = newRequest("?" + suffix + "=" + strconv.Itoa(vmax)) - resp = w.Result() - checkStatus(t, resp, http.StatusOK) - }) - } - - t.Run("limit", func(t *testing.T) { - t.Parallel() - checkValidate( - t, "index=0&sort=0&limit", 1, 100, - "limit must be an integer between 1 and 100", - ) - }) - - count := len(rosa.Collect()) - t.Run("index", func(t *testing.T) { - t.Parallel() - checkValidate( - t, "limit=1&sort=0&index", 0, count-1, - "index must be an integer between 0 and "+strconv.Itoa(count-1), - ) - }) - - t.Run("sort", func(t *testing.T) { - t.Parallel() - checkValidate( - t, "index=0&limit=1&sort", 0, int(sortOrderEnd), - "sort must be an integer between 0 and "+strconv.Itoa(int(sortOrderEnd)), - ) - }) -} -- cgit v1.3.1