From 6d8040d1bd25fd8073d1d6d330a96ccfb462e9d0 Mon Sep 17 00:00:00 2001 From: Milan Pavlik Date: Wed, 27 Apr 2022 19:28:58 +0000 Subject: [PATCH] [public-api] Add mock implementation of GetWorkspace --- .../public-api-server/integration_test.go | 2 +- components/public-api-server/main.go | 3 +- .../public-api-server/pkg/apiv1/workspace.go | 36 +++++++++++++++++++ .../pkg/apiv1/workspace_test.go | 35 ++++++++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 components/public-api-server/pkg/apiv1/workspace.go create mode 100644 components/public-api-server/pkg/apiv1/workspace_test.go diff --git a/components/public-api-server/integration_test.go b/components/public-api-server/integration_test.go index 962469d2261281..bf47c32ff11512 100644 --- a/components/public-api-server/integration_test.go +++ b/components/public-api-server/integration_test.go @@ -29,7 +29,7 @@ func TestPublicAPIServer_v1_WorkspaceService(t *testing.T) { workspaceClient := v1.NewWorkspacesServiceClient(conn) _, err = workspaceClient.GetWorkspace(ctx, &v1.GetWorkspaceRequest{}) - requireErrorStatusCode(t, codes.Unimplemented, err) + require.NoError(t, err) _, err = workspaceClient.ListWorkspaces(ctx, &v1.ListWorkspacesRequest{}) requireErrorStatusCode(t, codes.Unimplemented, err) diff --git a/components/public-api-server/main.go b/components/public-api-server/main.go index dd3b9701b19daa..3485140a3dca43 100644 --- a/components/public-api-server/main.go +++ b/components/public-api-server/main.go @@ -7,6 +7,7 @@ package main import ( "github.com/gitpod-io/gitpod/common-go/baseserver" "github.com/gitpod-io/gitpod/common-go/log" + "github.com/gitpod-io/gitpod/public-api-server/pkg/apiv1" v1 "github.com/gitpod-io/gitpod/public-api/v1" "net/http" ) @@ -36,7 +37,7 @@ func register(srv *baseserver.Server) error { _, _ = w.Write([]byte(`hello world`)) }) - v1.RegisterWorkspacesServiceServer(srv.GRPC(), v1.UnimplementedWorkspacesServiceServer{}) + v1.RegisterWorkspacesServiceServer(srv.GRPC(), apiv1.NewWorkspaceService()) v1.RegisterPrebuildsServiceServer(srv.GRPC(), v1.UnimplementedPrebuildsServiceServer{}) return nil diff --git a/components/public-api-server/pkg/apiv1/workspace.go b/components/public-api-server/pkg/apiv1/workspace.go new file mode 100644 index 00000000000000..b7b25e96a4ee64 --- /dev/null +++ b/components/public-api-server/pkg/apiv1/workspace.go @@ -0,0 +1,36 @@ +// Copyright (c) 2022 Gitpod GmbH. All rights reserved. +// Licensed under the GNU Affero General Public License (AGPL). +// See License-AGPL.txt in the project root for license information. + +package apiv1 + +import ( + "context" + v1 "github.com/gitpod-io/gitpod/public-api/v1" +) + +func NewWorkspaceService() *WorkspaceService { + return &WorkspaceService{ + UnimplementedWorkspacesServiceServer: &v1.UnimplementedWorkspacesServiceServer{}, + } +} + +type WorkspaceService struct { + *v1.UnimplementedWorkspacesServiceServer +} + +func (w *WorkspaceService) GetWorkspace(ctx context.Context, r *v1.GetWorkspaceRequest) (*v1.GetWorkspaceResponse, error) { + return &v1.GetWorkspaceResponse{ + ResponseStatus: nil, + Result: &v1.Workspace{ + WorkspaceId: r.GetWorkspaceId(), + OwnerId: "mock_owner", + ProjectId: "mock_project_id", + Context: &v1.WorkspaceContext{ + ContextUrl: "https://github.com/gitpod-io/gitpod", + Details: nil, + }, + Description: "This is a mock response", + }, + }, nil +} diff --git a/components/public-api-server/pkg/apiv1/workspace_test.go b/components/public-api-server/pkg/apiv1/workspace_test.go new file mode 100644 index 00000000000000..fb62a025d479fb --- /dev/null +++ b/components/public-api-server/pkg/apiv1/workspace_test.go @@ -0,0 +1,35 @@ +// Copyright (c) 2022 Gitpod GmbH. All rights reserved. +// Licensed under the GNU Affero General Public License (AGPL). +// See License-AGPL.txt in the project root for license information. + +package apiv1 + +import ( + "context" + v1 "github.com/gitpod-io/gitpod/public-api/v1" + "github.com/stretchr/testify/require" + "testing" +) + +func TestWorkspaceService_GetWorkspace(t *testing.T) { + svc := NewWorkspaceService() + + workspaceID := "some-workspace-id" + resp, err := svc.GetWorkspace(context.Background(), &v1.GetWorkspaceRequest{ + WorkspaceId: workspaceID, + }) + require.NoError(t, err) + require.Equal(t, &v1.GetWorkspaceResponse{ + ResponseStatus: nil, + Result: &v1.Workspace{ + WorkspaceId: workspaceID, + OwnerId: "mock_owner", + ProjectId: "mock_project_id", + Context: &v1.WorkspaceContext{ + ContextUrl: "https://github.com/gitpod-io/gitpod", + Details: nil, + }, + Description: "This is a mock response", + }, + }, resp) +}