Skip to content

Commit 202d703

Browse files
Laurie T. Malauroboquat
authored andcommitted
Transform getWorkspace response
1 parent 02a9589 commit 202d703

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

components/public-api-server/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/gitpod-io/gitpod/common-go v0.0.0-00010101000000-000000000000
77
github.com/gitpod-io/gitpod/gitpod-protocol v0.0.0-00010101000000-000000000000
88
github.com/gitpod-io/gitpod/public-api v0.0.0-00010101000000-000000000000
9+
github.com/google/go-cmp v0.5.7
910
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
1011
github.com/sirupsen/logrus v1.8.1
1112
github.com/spf13/cobra v1.4.0

components/public-api-server/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
123123
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
124124
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
125125
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
126+
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
126127
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
127128
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
128129
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=

components/public-api-server/pkg/apiv1/workspace.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,24 @@ func (w *WorkspaceService) GetWorkspace(ctx context.Context, r *v1.GetWorkspaceR
3737
return nil, status.Error(codes.Internal, "failed to establish connection to downstream services")
3838
}
3939

40-
// TODO(milan): Use resulting workspace and transform it to public API response
41-
_, err = server.GetWorkspace(ctx, r.GetWorkspaceId())
40+
workspace, err := server.GetWorkspace(ctx, r.GetWorkspaceId())
4241
if err != nil {
4342
return nil, status.Error(codes.NotFound, "failed to get workspace")
4443
}
4544

4645
return &v1.GetWorkspaceResponse{
4746
Result: &v1.Workspace{
48-
WorkspaceId: r.GetWorkspaceId(),
49-
OwnerId: "mock_owner",
50-
ProjectId: "mock_project_id",
47+
WorkspaceId: workspace.Workspace.ID,
48+
OwnerId: workspace.Workspace.OwnerID,
49+
ProjectId: "",
5150
Context: &v1.WorkspaceContext{
52-
ContextUrl: "https://github.com/gitpod-io/gitpod",
53-
Details: nil,
51+
ContextUrl: workspace.Workspace.ContextURL,
52+
Details: &v1.WorkspaceContext_Git_{Git: &v1.WorkspaceContext_Git{
53+
NormalizedContextUrl: workspace.Workspace.ContextURL,
54+
Commit: "",
55+
}},
5456
},
55-
Description: "This is a mock response",
57+
Description: workspace.Workspace.Description,
5658
},
5759
}, nil
5860
}

components/public-api-server/pkg/apiv1/workspace_test.go

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,24 @@ import (
1010
"github.com/gitpod-io/gitpod/common-go/baseserver"
1111
gitpod "github.com/gitpod-io/gitpod/gitpod-protocol"
1212
v1 "github.com/gitpod-io/gitpod/public-api/v1"
13+
"github.com/google/go-cmp/cmp"
1314
"github.com/stretchr/testify/require"
1415
"google.golang.org/grpc"
1516
"google.golang.org/grpc/codes"
1617
"google.golang.org/grpc/credentials/insecure"
1718
"google.golang.org/grpc/metadata"
1819
"google.golang.org/grpc/status"
19-
"google.golang.org/protobuf/proto"
20+
"google.golang.org/protobuf/testing/protocmp"
2021
"testing"
2122
)
2223

2324
func TestWorkspaceService_GetWorkspace(t *testing.T) {
2425
const (
2526
bearerToken = "bearer-token-for-tests"
2627
foundWorkspaceID = "easycz-seer-xl8o1zacpyw"
28+
contextURL = "https://github.com/gitpod/pull/1111"
29+
ownerID = "c6zz4631-3bbc-4hj4-be80-3dd05c66ee4e"
30+
description = "This is the description"
2731
)
2832

2933
srv := baseserver.NewForTests(t)
@@ -32,7 +36,26 @@ func TestWorkspaceService_GetWorkspace(t *testing.T) {
3236
api: &FakeGitpodAPI{workspaces: map[string]*gitpod.WorkspaceInfo{
3337
foundWorkspaceID: {
3438
LatestInstance: &gitpod.WorkspaceInstance{},
35-
Workspace: &gitpod.Workspace{},
39+
Workspace: &gitpod.Workspace{
40+
BaseImageNameResolved: "",
41+
BasedOnPrebuildID: "",
42+
BasedOnSnapshotID: "",
43+
Config: nil,
44+
ContentDeletedTime: "",
45+
Context: nil,
46+
ContextURL: contextURL,
47+
CreationTime: "",
48+
Deleted: false,
49+
Description: description,
50+
ID: foundWorkspaceID,
51+
ImageNameResolved: "",
52+
ImageSource: nil,
53+
OwnerID: ownerID,
54+
Pinned: false,
55+
Shareable: false,
56+
SoftDeleted: "",
57+
Type: "",
58+
},
3659
},
3760
}},
3861
}
@@ -60,13 +83,16 @@ func TestWorkspaceService_GetWorkspace(t *testing.T) {
6083
Response: &v1.GetWorkspaceResponse{
6184
Result: &v1.Workspace{
6285
WorkspaceId: foundWorkspaceID,
63-
OwnerId: "mock_owner",
64-
ProjectId: "mock_project_id",
86+
OwnerId: ownerID,
87+
ProjectId: "",
6588
Context: &v1.WorkspaceContext{
66-
ContextUrl: "https://github.com/gitpod-io/gitpod",
67-
Details: nil,
89+
ContextUrl: contextURL,
90+
Details: &v1.WorkspaceContext_Git_{Git: &v1.WorkspaceContext_Git{
91+
NormalizedContextUrl: contextURL,
92+
Commit: "",
93+
}},
6894
},
69-
Description: "This is a mock response",
95+
Description: description,
7096
},
7197
},
7298
},
@@ -84,7 +110,9 @@ func TestWorkspaceService_GetWorkspace(t *testing.T) {
84110
WorkspaceId: scenario.WorkspaceID,
85111
})
86112
require.Equal(t, scenario.ErrorCode, status.Code(err), "status code must match")
87-
require.True(t, proto.Equal(scenario.Response, resp))
113+
if diff := cmp.Diff(scenario.Response, resp, protocmp.Transform()); diff != "" {
114+
t.Errorf("unexpected difference:\n%v", diff)
115+
}
88116
})
89117

90118
}

0 commit comments

Comments
 (0)