Path: blob/main/components/public-api-server/pkg/apiv1/editor_service_test.go
2499 views
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package apiv156import (7"context"8"net/http"9"net/http/httptest"10"testing"1112"github.com/bufbuild/connect-go"13"github.com/gitpod-io/gitpod/components/public-api/go/config"14v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"15"github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1/v1connect"16protocol "github.com/gitpod-io/gitpod/gitpod-protocol"17"github.com/gitpod-io/gitpod/public-api-server/pkg/auth"18"github.com/gitpod-io/gitpod/public-api-server/pkg/jws"19"github.com/gitpod-io/gitpod/public-api-server/pkg/jws/jwstest"20"github.com/golang/mock/gomock"21"github.com/stretchr/testify/require"22)2324func TestEditorService_ListEditorOptions(t *testing.T) {25t.Run("proxies request to server", func(t *testing.T) {26serverMock, client := setupEditorService(t)2728serverMock.EXPECT().GetIDEOptions(gomock.Any()).Return(&protocol.IDEOptions{Options: map[string]protocol.IDEOption{29"code": {30OrderKey: "02",31Title: "VS Code",32Logo: "https://gitpod.io/icons/vscode.svg",33ImageVersion: "1.68.0",34LatestImageVersion: "1.69.0",35},36"theia": {37OrderKey: "01",38Title: "Theia",39Logo: "https://gitpod.io/icons/theia.svg",40ImageVersion: "1.68.0",41},42}, DefaultIde: "", DefaultDesktopIde: "", Clients: map[string]protocol.IDEClient{}}, nil)4344retrieved, err := client.ListEditorOptions(context.Background(), connect.NewRequest(&v1.ListEditorOptionsRequest{}))45require.NoError(t, err)46requireEqualProto(t, &v1.ListEditorOptionsResponse{47Result: []*v1.EditorOption{48{49Title: "Theia",50Id: "theia",51Logo: "https://gitpod.io/icons/theia.svg",52Stable: &v1.EditorOption_Kind{53Version: "1.68.0",54},55Latest: &v1.EditorOption_Kind{},56},57{58Title: "VS Code",59Id: "code",60Logo: "https://gitpod.io/icons/vscode.svg",61Stable: &v1.EditorOption_Kind{62Version: "1.68.0",63},64Latest: &v1.EditorOption_Kind{65Version: "1.69.0",66},67},68},69}, retrieved.Msg)70})71}7273func setupEditorService(t *testing.T) (*protocol.MockAPIInterface, v1connect.EditorServiceClient) {74t.Helper()7576ctrl := gomock.NewController(t)77t.Cleanup(ctrl.Finish)7879serverMock := protocol.NewMockAPIInterface(ctrl)8081svc := NewEditorService(&FakeServerConnPool{82api: serverMock,83})8485keyset := jwstest.GenerateKeySet(t)86rsa256, err := jws.NewRSA256(keyset)87require.NoError(t, err)8889_, handler := v1connect.NewEditorServiceHandler(svc, connect.WithInterceptors(auth.NewServerInterceptor(config.SessionConfig{90Issuer: "unitetest.com",91Cookie: config.CookieConfig{92Name: "cookie_jwt",93},94}, rsa256)))9596srv := httptest.NewServer(handler)97t.Cleanup(srv.Close)9899client := v1connect.NewEditorServiceClient(http.DefaultClient, srv.URL, connect.WithInterceptors(100auth.NewClientInterceptor("auth-token"),101))102103return serverMock, client104}105106107