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