Path: blob/main/components/local-app/cmd/workspace-list_test.go
2497 views
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package cmd56import (7"context"8"net/http"9"testing"1011"github.com/bufbuild/connect-go"12v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"13gitpod_experimental_v1connect "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1/v1connect"14"github.com/gitpod-io/local-app/pkg/config"15)1617func TestWorkspaceListCmd(t *testing.T) {18RunCommandTests(t, []CommandTest{19{20Name: "no config",21Commandline: []string{"workspace", "list"},22Expectation: CommandTestExpectation{23Error: config.ErrNoContext.Error(),24HasResolutions: true,25},26},27{28Name: "test one workspace",29Commandline: []string{"workspace", "list"},30Config: &config.Config{31ActiveContext: "test",32},33PrepServer: func(mux *http.ServeMux) {34mux.Handle(gitpod_experimental_v1connect.NewWorkspacesServiceHandler(&testWorkspaceListCmdWorkspaceSrv{35Resp: &v1.ListWorkspacesResponse{36Result: []*v1.Workspace{fixtureWorkspace()},37},38}))39},40Expectation: CommandTestExpectation{41Output: "ID REPOSITORY BRANCH STATUS \nworkspaceID owner/name running \n",42},43},44{45Name: "test no workspace",46Commandline: []string{"workspace", "list"},47Config: &config.Config{48ActiveContext: "test",49},50PrepServer: func(mux *http.ServeMux) {51mux.Handle(gitpod_experimental_v1connect.NewWorkspacesServiceHandler(&testWorkspaceListCmdWorkspaceSrv{52Resp: &v1.ListWorkspacesResponse{53Result: []*v1.Workspace{},54},55}))56},57Expectation: CommandTestExpectation{58Output: "ID REPOSITORY BRANCH STATUS \n",59},60},61})62}6364type testWorkspaceListCmdWorkspaceSrv struct {65Resp *v1.ListWorkspacesResponse66Err error67gitpod_experimental_v1connect.UnimplementedWorkspacesServiceHandler68}6970func (srv testWorkspaceListCmdWorkspaceSrv) ListWorkspaces(context.Context, *connect.Request[v1.ListWorkspacesRequest]) (*connect.Response[v1.ListWorkspacesResponse], error) {71if srv.Err != nil {72return nil, srv.Err73}74return &connect.Response[v1.ListWorkspacesResponse]{Msg: srv.Resp}, nil75}767778