Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/public-api/go/client/client_test.go
2500 views
1
// Copyright (c) 2022 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 client
6
7
import (
8
"net/http"
9
"testing"
10
11
"github.com/stretchr/testify/require"
12
)
13
14
func TestNew(t *testing.T) {
15
16
t.Run("with all options", func(t *testing.T) {
17
expectedOptions := &options{
18
url: "https://foo.bar.com",
19
client: &http.Client{},
20
credentials: "my_awesome_credentials",
21
}
22
gitpod, err := New(
23
WithURL(expectedOptions.url),
24
WithCredentials(expectedOptions.credentials),
25
WithHTTPClient(expectedOptions.client),
26
)
27
require.NoError(t, err)
28
require.Equal(t, expectedOptions, gitpod.cfg)
29
30
require.NotNil(t, gitpod.PersonalAccessTokens)
31
require.NotNil(t, gitpod.Workspaces)
32
require.NotNil(t, gitpod.Projects)
33
require.NotNil(t, gitpod.PersonalAccessTokens)
34
require.NotNil(t, gitpod.User)
35
})
36
37
t.Run("fails when no credentials specified", func(t *testing.T) {
38
_, err := New()
39
require.Error(t, err)
40
})
41
42
t.Run("defaults to https://api.gitpod.io", func(t *testing.T) {
43
gitpod, err := New(WithCredentials("foo"))
44
require.NoError(t, err)
45
46
require.Equal(t, "https://api.gitpod.io", gitpod.cfg.url)
47
})
48
49
}
50
51