4
4
* See License.AGPL.txt in the project root for license information.
5
5
*/
6
6
7
+ import * as grpc from "@grpc/grpc-js" ;
7
8
import { v1 } from "@authzed/authzed-node" ;
8
9
import { IAnalyticsWriter , NullAnalyticsWriter } from "@gitpod/gitpod-protocol/lib/analytics" ;
9
- import { IDEServiceDefinition } from "@gitpod/ide-service-api/lib/ide.pb" ;
10
+ import { IDEServiceClient , IDEServiceDefinition } from "@gitpod/ide-service-api/lib/ide.pb" ;
10
11
import { UsageServiceDefinition } from "@gitpod/usage-api/lib/usage/v1/usage.pb" ;
11
- import { WorkspaceManagerClientProvider } from "@gitpod/ws-manager/lib/client-provider" ;
12
12
import { ContainerModule } from "inversify" ;
13
13
import { v4 } from "uuid" ;
14
14
import { AuthProviderParams } from "../auth/auth-provider" ;
15
- import { HostContextProviderFactory } from "../auth/host-context-provider" ;
15
+ import { HostContextProvider , HostContextProviderFactory } from "../auth/host-context-provider" ;
16
16
import { HostContextProviderImpl } from "../auth/host-context-provider-impl" ;
17
17
import { SpiceDBClient } from "../authorization/spicedb" ;
18
18
import { Config } from "../config" ;
@@ -21,7 +21,22 @@ import { testContainer } from "@gitpod/gitpod-db/lib";
21
21
import { productionContainerModule } from "../container-module" ;
22
22
import { createMock } from "./mocks/mock" ;
23
23
import { UsageServiceClientMock } from "./mocks/usage-service-client-mock" ;
24
- import { env } from "process" ;
24
+ import { env , nextTick } from "process" ;
25
+ import { WorkspaceManagerClientProviderSource } from "@gitpod/ws-manager/lib/client-provider-source" ;
26
+ import { WorkspaceClusterWoTLS } from "@gitpod/gitpod-protocol/lib/workspace-cluster" ;
27
+ import { WorkspaceManagerClientProvider } from "@gitpod/ws-manager/lib/client-provider" ;
28
+ import {
29
+ BuildInfo ,
30
+ BuildResponse ,
31
+ BuildStatus ,
32
+ IImageBuilderClient ,
33
+ LogInfo ,
34
+ ResolveWorkspaceImageResponse ,
35
+ } from "@gitpod/image-builder/lib" ;
36
+ import { IWorkspaceManagerClient , StartWorkspaceResponse } from "@gitpod/ws-manager/lib" ;
37
+ import { TokenProvider } from "../user/token-provider" ;
38
+ import { GitHubScope } from "../github/scopes" ;
39
+ import { GitpodHostUrl } from "@gitpod/gitpod-protocol/lib/util/gitpod-host-url" ;
25
40
26
41
/**
27
42
* Expects a fully configured production container and
@@ -30,19 +45,141 @@ import { env } from "process";
30
45
* - replaces the analytics writer with a null analytics writer
31
46
*/
32
47
const mockApplyingContainerModule = new ContainerModule ( ( bind , unbound , isbound , rebind ) => {
48
+ rebind ( HostContextProvider ) . toConstantValue ( {
49
+ get : ( ) => {
50
+ const authProviderId = "Public-GitHub" ;
51
+ return {
52
+ authProvider : {
53
+ authProviderId,
54
+ } ,
55
+ } ;
56
+ } ,
57
+ } ) ;
58
+ rebind ( TokenProvider ) . toConstantValue ( < TokenProvider > {
59
+ getTokenForHost : async ( ) => {
60
+ return {
61
+ value : "test" ,
62
+ scopes : [ GitHubScope . EMAIL , GitHubScope . PUBLIC , GitHubScope . PRIVATE ] ,
63
+ } ;
64
+ } ,
65
+ } ) ;
33
66
rebind ( UsageServiceDefinition . name ) . toConstantValue ( createMock ( new UsageServiceClientMock ( ) ) ) ;
34
67
rebind ( StorageClient ) . toConstantValue ( createMock ( ) ) ;
35
- rebind ( WorkspaceManagerClientProvider ) . toConstantValue ( createMock ( ) ) ;
36
- rebind ( IDEServiceDefinition . name ) . toConstantValue ( createMock ( ) ) ;
68
+ rebind ( WorkspaceManagerClientProviderSource ) . toDynamicValue ( ( ) : WorkspaceManagerClientProviderSource => {
69
+ const clusters : WorkspaceClusterWoTLS [ ] = [
70
+ {
71
+ name : "eu-central-1" ,
72
+ region : "europe" ,
73
+ url : "https://ws.gitpod.io" ,
74
+ state : "available" ,
75
+ maxScore : 100 ,
76
+ score : 100 ,
77
+ govern : true ,
78
+ } ,
79
+ ] ;
80
+ return < WorkspaceManagerClientProviderSource > {
81
+ getAllWorkspaceClusters : async ( ) => {
82
+ return clusters ;
83
+ } ,
84
+ getWorkspaceCluster : async ( name : string ) => {
85
+ return clusters . find ( ( c ) => c . name === name ) ;
86
+ } ,
87
+ } ;
88
+ } ) ;
89
+ rebind ( WorkspaceManagerClientProvider )
90
+ . toSelf ( )
91
+ . onActivation ( ( _ , provider ) => {
92
+ provider [ "createConnection" ] = ( ) => {
93
+ const channel = < Partial < grpc . Channel > > {
94
+ getConnectivityState ( ) {
95
+ return grpc . connectivityState . READY ;
96
+ } ,
97
+ } ;
98
+ return Object . assign (
99
+ < Partial < grpc . Client > > {
100
+ getChannel ( ) {
101
+ return channel ;
102
+ } ,
103
+ } ,
104
+ < IImageBuilderClient & IWorkspaceManagerClient > {
105
+ resolveWorkspaceImage ( request , metadata , options , callback ) {
106
+ const response = new ResolveWorkspaceImageResponse ( ) ;
107
+ response . setStatus ( BuildStatus . DONE_SUCCESS ) ;
108
+ callback ( null , response ) ;
109
+ } ,
110
+ build ( request , metadata , options ) {
111
+ const listeners = new Map < string | symbol , Function > ( ) ;
112
+ nextTick ( ( ) => {
113
+ const response = new BuildResponse ( ) ;
114
+ response . setStatus ( BuildStatus . DONE_SUCCESS ) ;
115
+ response . setRef ( "my-test-build-ref" ) ;
116
+ const buildInfo = new BuildInfo ( ) ;
117
+ const logInfo = new LogInfo ( ) ;
118
+ logInfo . setUrl ( "https://ws.gitpod.io/my-test-image-build/logs" ) ;
119
+ buildInfo . setLogInfo ( logInfo ) ;
120
+ response . setInfo ( buildInfo ) ;
121
+ listeners . get ( "data" ) ! ( response ) ;
122
+ listeners . get ( "end" ) ! ( ) ;
123
+ } ) ;
124
+ return {
125
+ on ( event , callback ) {
126
+ listeners . set ( event , callback ) ;
127
+ } ,
128
+ } ;
129
+ } ,
130
+ startWorkspace ( request , metadata , options , callback ) {
131
+ const workspaceId = request . getServicePrefix ( ) ;
132
+ const response = new StartWorkspaceResponse ( ) ;
133
+ response . setUrl ( `https://${ workspaceId } .ws.gitpod.io` ) ;
134
+ callback ( null , response ) ;
135
+ } ,
136
+ } ,
137
+ ) as any ;
138
+ } ;
139
+ return provider ;
140
+ } ) ;
141
+ rebind ( IDEServiceDefinition . name ) . toConstantValue (
142
+ createMock ( < Partial < IDEServiceClient > > {
143
+ async resolveWorkspaceConfig ( ) {
144
+ return {
145
+ envvars : [ ] ,
146
+ supervisorImage : "gitpod/supervisor:latest" ,
147
+ webImage : "gitpod/code:latest" ,
148
+ ideImageLayers : [ ] ,
149
+ refererIde : "code" ,
150
+ ideSettings : "" ,
151
+ tasks : "" ,
152
+ } ;
153
+ } ,
154
+ } ) ,
155
+ ) ;
37
156
38
157
rebind < Partial < Config > > ( Config ) . toConstantValue ( {
158
+ hostUrl : new GitpodHostUrl ( "https://gitpod.io" ) ,
39
159
blockNewUsers : {
40
160
enabled : false ,
41
161
passlist : [ ] ,
42
162
} ,
43
163
redis : {
44
164
address : ( env . REDIS_HOST || "127.0.0.1" ) + ":" + ( env . REDIS_PORT || "6379" ) ,
45
165
} ,
166
+ workspaceDefaults : {
167
+ workspaceImage : "gitpod/workspace-full" ,
168
+ defaultFeatureFlags : [ ] ,
169
+ previewFeatureFlags : [ ] ,
170
+ } ,
171
+ workspaceClasses : [
172
+ {
173
+ category : "general" ,
174
+ description : "The default workspace class" ,
175
+ displayName : "Default" ,
176
+ id : "default" ,
177
+ isDefault : true ,
178
+ powerups : 0 ,
179
+ } ,
180
+ ] ,
181
+ authProviderConfigs : [ ] ,
182
+ installationShortname : "gitpod" ,
46
183
} ) ;
47
184
rebind ( IAnalyticsWriter ) . toConstantValue ( NullAnalyticsWriter ) ;
48
185
rebind ( HostContextProviderFactory )
0 commit comments