diff --git a/internal/backend/releases_test.go b/internal/backend/releases_test.go index 50a7c11..3faadfa 100644 --- a/internal/backend/releases_test.go +++ b/internal/backend/releases_test.go @@ -52,6 +52,26 @@ func TestReleaseService(t *testing.T) { assert.ErrorIs(t, err, ErrNotFound) } +func TestReleaseServiceLinuxBinaryAndPackage(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + json.NewEncoder(w).Encode(giteaRelease{Id: 1, Name: "v1.9.0", Assets: []giteaAsset{ + {Name: "MusicPlayer_1.9.0.exe", DownloadUrl: "https://example.com/exe"}, + {Name: "MusicPlayer_1.9.0_linux.tar.gz", DownloadUrl: "https://example.com/package"}, + {Name: "MusicPlayer_1.9.0.x86_64", DownloadUrl: "https://example.com/binary"}, + }}) + })) + t.Cleanup(server.Close) + r := NewReleaseService(server.URL) + ctx := context.Background() + + binary, err := r.AssetURL(ctx, ".x86_64") + require.NoError(t, err) + assert.Equal(t, "https://example.com/binary", binary) + pkg, err := r.AssetURL(ctx, "_linux.tar.gz") + require.NoError(t, err) + assert.Equal(t, "https://example.com/package", pkg) +} + func TestReleaseServiceCachesRelease(t *testing.T) { server, calls := newGitea(t, http.StatusOK) r := NewReleaseService(server.URL) diff --git a/internal/server/handlers_test.go b/internal/server/handlers_test.go index bcefcac..1470f45 100644 --- a/internal/server/handlers_test.go +++ b/internal/server/handlers_test.go @@ -222,7 +222,27 @@ func TestDownloadEndpoints(t *testing.T) { assert.Equal(t, http.StatusFound, rec.Code) assert.Equal(t, "https://example.com/Player.exe", rec.Header().Get("Location")) + // A release without Linux files, like those before 1.9. assert.Equal(t, http.StatusNotFound, e.do(http.MethodGet, "/api/v1/download/linux").Code) + assert.Equal(t, http.StatusNotFound, e.do(http.MethodGet, "/api/v1/download/linux-package").Code) +} + +func TestDownloadLinuxBinaryAndPackage(t *testing.T) { + gitea := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte(`{"id":1,"name":"v1.9.0","assets":[` + + `{"name":"MusicPlayer_1.9.0_linux.tar.gz","browser_download_url":"https://example.com/package"},` + + `{"name":"MusicPlayer_1.9.0.x86_64","browser_download_url":"https://example.com/binary"}]}`)) + })) + t.Cleanup(gitea.Close) + e := newTestEnv(t, func(c *config.Config) { c.ReleasesURL = gitea.URL }) + + rec := e.do(http.MethodGet, "/api/v1/download/linux") + assert.Equal(t, http.StatusFound, rec.Code) + assert.Equal(t, "https://example.com/binary", rec.Header().Get("Location"), "the bare binary, for updating in place") + + rec = e.do(http.MethodGet, "/api/v1/download/linux-package") + assert.Equal(t, http.StatusFound, rec.Code) + assert.Equal(t, "https://example.com/package", rec.Header().Get("Location")) } func TestDownloadUpstreamDown(t *testing.T) { diff --git a/internal/server/misc_handler.go b/internal/server/misc_handler.go index 59f9a42..0d56c51 100644 --- a/internal/server/misc_handler.go +++ b/internal/server/misc_handler.go @@ -102,4 +102,6 @@ func (s *Server) registerMisc(a huma.API) { } download("download-client-windows", "/download/windows", "Windows", ".exe") download("download-client-linux", "/download/linux", "Linux", ".x86_64") + // The package has the icon, a menu entry and install.sh. Releases before 1.9 have none (404). + download("download-client-linux-package", "/download/linux-package", "Linux (package with installer)", "_linux.tar.gz") } diff --git a/internal/server/openapi_test.go b/internal/server/openapi_test.go index bbf3137..4d4a2ad 100644 --- a/internal/server/openapi_test.go +++ b/internal/server/openapi_test.go @@ -81,6 +81,7 @@ func TestOpenAPIDocumentsTheV1API(t *testing.T) { "GET /api/v1/character/list", "GET /api/v1/download", "GET /api/v1/download/linux", + "GET /api/v1/download/linux-package", "GET /api/v1/download/list", "GET /api/v1/download/windows", "GET /api/v1/health", @@ -235,6 +236,7 @@ func TestResponsesMatchOpenAPI(t *testing.T) { v.check(http.MethodGet, "/api/v1/download/list", "", http.StatusOK) v.check(http.MethodGet, "/api/v1/download/windows", "", http.StatusFound) v.check(http.MethodGet, "/api/v1/download/linux", "", http.StatusNotFound) + v.check(http.MethodGet, "/api/v1/download/linux-package", "", http.StatusNotFound) v.check(http.MethodGet, "/api/v1/health", "", http.StatusOK) v.check(http.MethodGet, "/api/v1/version", "", http.StatusOK) v.check(http.MethodGet, "/api/v1/version/history", "", http.StatusOK)