-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.go
More file actions
68 lines (59 loc) · 1.32 KB
/
client_test.go
File metadata and controls
68 lines (59 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-FileCopyrightText: Copyright 2025 Carabiner Systems, Inc
// SPDX-License-Identifier: Apache-2.0
package github
import (
"errors"
"fmt"
"io"
"net/http"
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestTokenScopes(t *testing.T) {
t.Parallel()
token := os.Getenv("GITHUB_TOKEN")
if token == "" {
t.Skip()
}
c, err := NewClient()
require.NoError(t, err)
scopes, err := c.TokenScopes()
require.NoError(t, err)
fmt.Printf("%+v\n", scopes)
require.NotNil(t, scopes)
t.Error()
}
func TestCall(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
name string
data []byte
synthErr error
}{
{"normal", []byte("Hi\n"), nil},
{"normal", nil, errors.New("Superbad HTTP Error!")},
} {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
// Initialize the caller with the file caller to test
c, err := NewClient(
WithCaller(&FileCaller{
SourcePath: "testdata/file.txt",
Error: tc.synthErr,
}),
)
require.NoError(t, err)
res, err := c.Call(t.Context(), http.MethodGet, "http://example.com/", nil)
if tc.synthErr != nil {
require.Error(t, err)
return
}
require.NoError(t, err)
defer res.Body.Close() //nolint:errcheck
data, err := io.ReadAll(res.Body)
require.NoError(t, err)
require.Equal(t, tc.data, data)
})
}
}