Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/local-app/cmd/workspace-list_test.go
2497 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 cmd
6
7
import (
8
"context"
9
"net/http"
10
"testing"
11
12
"github.com/bufbuild/connect-go"
13
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"
14
gitpod_experimental_v1connect "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1/v1connect"
15
"github.com/gitpod-io/local-app/pkg/config"
16
)
17
18
func TestWorkspaceListCmd(t *testing.T) {
19
RunCommandTests(t, []CommandTest{
20
{
21
Name: "no config",
22
Commandline: []string{"workspace", "list"},
23
Expectation: CommandTestExpectation{
24
Error: config.ErrNoContext.Error(),
25
HasResolutions: true,
26
},
27
},
28
{
29
Name: "test one workspace",
30
Commandline: []string{"workspace", "list"},
31
Config: &config.Config{
32
ActiveContext: "test",
33
},
34
PrepServer: func(mux *http.ServeMux) {
35
mux.Handle(gitpod_experimental_v1connect.NewWorkspacesServiceHandler(&testWorkspaceListCmdWorkspaceSrv{
36
Resp: &v1.ListWorkspacesResponse{
37
Result: []*v1.Workspace{fixtureWorkspace()},
38
},
39
}))
40
},
41
Expectation: CommandTestExpectation{
42
Output: "ID REPOSITORY BRANCH STATUS \nworkspaceID owner/name running \n",
43
},
44
},
45
{
46
Name: "test no workspace",
47
Commandline: []string{"workspace", "list"},
48
Config: &config.Config{
49
ActiveContext: "test",
50
},
51
PrepServer: func(mux *http.ServeMux) {
52
mux.Handle(gitpod_experimental_v1connect.NewWorkspacesServiceHandler(&testWorkspaceListCmdWorkspaceSrv{
53
Resp: &v1.ListWorkspacesResponse{
54
Result: []*v1.Workspace{},
55
},
56
}))
57
},
58
Expectation: CommandTestExpectation{
59
Output: "ID REPOSITORY BRANCH STATUS \n",
60
},
61
},
62
})
63
}
64
65
type testWorkspaceListCmdWorkspaceSrv struct {
66
Resp *v1.ListWorkspacesResponse
67
Err error
68
gitpod_experimental_v1connect.UnimplementedWorkspacesServiceHandler
69
}
70
71
func (srv testWorkspaceListCmdWorkspaceSrv) ListWorkspaces(context.Context, *connect.Request[v1.ListWorkspacesRequest]) (*connect.Response[v1.ListWorkspacesResponse], error) {
72
if srv.Err != nil {
73
return nil, srv.Err
74
}
75
return &connect.Response[v1.ListWorkspacesResponse]{Msg: srv.Resp}, nil
76
}
77
78