Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/local-app/cmd/login_test.go
3601 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
"fmt"
10
"net/http"
11
"testing"
12
13
"github.com/bufbuild/connect-go"
14
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"
15
gitpod_experimental_v1connect "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1/v1connect"
16
"github.com/gitpod-io/local-app/pkg/config"
17
)
18
19
func TestLoginCmd(t *testing.T) {
20
RunCommandTests(t, []CommandTest{
21
{
22
Name: "test unauthenticated",
23
Commandline: []string{"login", "--token", "foo"},
24
Config: &config.Config{
25
ActiveContext: "test",
26
},
27
PrepServer: func(mux *http.ServeMux) {
28
mux.Handle(gitpod_experimental_v1connect.NewTeamsServiceHandler(&testLoginCmdSrv{
29
Err: connect.NewError(connect.CodeUnauthenticated, fmt.Errorf("cannot establish caller identity")),
30
}))
31
},
32
Expectation: CommandTestExpectation{
33
Error: "unauthenticated",
34
HasResolutions: true,
35
},
36
},
37
})
38
}
39
40
type testLoginCmdSrv struct {
41
Err error
42
gitpod_experimental_v1connect.UnimplementedTeamsServiceHandler
43
}
44
45
func (srv testLoginCmdSrv) ListTeams(context.Context, *connect.Request[v1.ListTeamsRequest]) (*connect.Response[v1.ListTeamsResponse], error) {
46
return nil, srv.Err
47
}
48
49