Skip to content

Commit

Permalink
Transform getWorkspace response
Browse files Browse the repository at this point in the history
  • Loading branch information
laushinka authored and roboquat committed May 6, 2022
1 parent 02a9589 commit 202d703
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
1 change: 1 addition & 0 deletions components/public-api-server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/gitpod-io/gitpod/common-go v0.0.0-00010101000000-000000000000
github.com/gitpod-io/gitpod/gitpod-protocol v0.0.0-00010101000000-000000000000
github.com/gitpod-io/gitpod/public-api v0.0.0-00010101000000-000000000000
github.com/google/go-cmp v0.5.7
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.4.0
Expand Down
1 change: 1 addition & 0 deletions components/public-api-server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
Expand Down
18 changes: 10 additions & 8 deletions components/public-api-server/pkg/apiv1/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,24 @@ func (w *WorkspaceService) GetWorkspace(ctx context.Context, r *v1.GetWorkspaceR
return nil, status.Error(codes.Internal, "failed to establish connection to downstream services")
}

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

return &v1.GetWorkspaceResponse{
Result: &v1.Workspace{
WorkspaceId: r.GetWorkspaceId(),
OwnerId: "mock_owner",
ProjectId: "mock_project_id",
WorkspaceId: workspace.Workspace.ID,
OwnerId: workspace.Workspace.OwnerID,
ProjectId: "",
Context: &v1.WorkspaceContext{
ContextUrl: "https://github.com/gitpod-io/gitpod",
Details: nil,
ContextUrl: workspace.Workspace.ContextURL,
Details: &v1.WorkspaceContext_Git_{Git: &v1.WorkspaceContext_Git{
NormalizedContextUrl: workspace.Workspace.ContextURL,
Commit: "",
}},
},
Description: "This is a mock response",
Description: workspace.Workspace.Description,
},
}, nil
}
Expand Down
44 changes: 36 additions & 8 deletions components/public-api-server/pkg/apiv1/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ import (
"github.com/gitpod-io/gitpod/common-go/baseserver"
gitpod "github.com/gitpod-io/gitpod/gitpod-protocol"
v1 "github.com/gitpod-io/gitpod/public-api/v1"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protocmp"
"testing"
)

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

srv := baseserver.NewForTests(t)
Expand All @@ -32,7 +36,26 @@ func TestWorkspaceService_GetWorkspace(t *testing.T) {
api: &FakeGitpodAPI{workspaces: map[string]*gitpod.WorkspaceInfo{
foundWorkspaceID: {
LatestInstance: &gitpod.WorkspaceInstance{},
Workspace: &gitpod.Workspace{},
Workspace: &gitpod.Workspace{
BaseImageNameResolved: "",
BasedOnPrebuildID: "",
BasedOnSnapshotID: "",
Config: nil,
ContentDeletedTime: "",
Context: nil,
ContextURL: contextURL,
CreationTime: "",
Deleted: false,
Description: description,
ID: foundWorkspaceID,
ImageNameResolved: "",
ImageSource: nil,
OwnerID: ownerID,
Pinned: false,
Shareable: false,
SoftDeleted: "",
Type: "",
},
},
}},
}
Expand Down Expand Up @@ -60,13 +83,16 @@ func TestWorkspaceService_GetWorkspace(t *testing.T) {
Response: &v1.GetWorkspaceResponse{
Result: &v1.Workspace{
WorkspaceId: foundWorkspaceID,
OwnerId: "mock_owner",
ProjectId: "mock_project_id",
OwnerId: ownerID,
ProjectId: "",
Context: &v1.WorkspaceContext{
ContextUrl: "https://github.com/gitpod-io/gitpod",
Details: nil,
ContextUrl: contextURL,
Details: &v1.WorkspaceContext_Git_{Git: &v1.WorkspaceContext_Git{
NormalizedContextUrl: contextURL,
Commit: "",
}},
},
Description: "This is a mock response",
Description: description,
},
},
},
Expand All @@ -84,7 +110,9 @@ func TestWorkspaceService_GetWorkspace(t *testing.T) {
WorkspaceId: scenario.WorkspaceID,
})
require.Equal(t, scenario.ErrorCode, status.Code(err), "status code must match")
require.True(t, proto.Equal(scenario.Response, resp))
if diff := cmp.Diff(scenario.Response, resp, protocmp.Transform()); diff != "" {
t.Errorf("unexpected difference:\n%v", diff)
}
})

}
Expand Down

0 comments on commit 202d703

Please sign in to comment.