-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathshortcuts_test.go
More file actions
63 lines (50 loc) · 1.94 KB
/
Copy pathshortcuts_test.go
File metadata and controls
63 lines (50 loc) · 1.94 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
package cli
import (
"encoding/json"
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/xdevplatform/xurl/api"
)
type fakeClient struct {
sendRequest func(options api.RequestOptions) (json.RawMessage, error)
}
func (f fakeClient) BuildRequest(options api.RequestOptions) (*http.Request, error) {
return nil, fmt.Errorf("not implemented")
}
func (f fakeClient) BuildMultipartRequest(options api.MultipartOptions) (*http.Request, error) {
return nil, fmt.Errorf("not implemented")
}
func (f fakeClient) SendRequest(options api.RequestOptions) (json.RawMessage, error) {
return f.sendRequest(options)
}
func (f fakeClient) StreamRequest(options api.RequestOptions) error {
return fmt.Errorf("not implemented")
}
func (f fakeClient) SendMultipartRequest(options api.MultipartOptions) (json.RawMessage, error) {
return nil, fmt.Errorf("not implemented")
}
func TestResolveMyUserIDUsesUsernameFallback(t *testing.T) {
client := fakeClient{
sendRequest: func(options api.RequestOptions) (json.RawMessage, error) {
require.Equal(t, "/2/users/by/username/alice?user.fields=created_at,description,public_metrics,verified,verified_type,subscription_type,profile_image_url", options.Endpoint)
return json.RawMessage(`{"data":{"id":"42"}}`), nil
},
}
userID, err := resolveMyUserID(client, api.RequestOptions{Username: "alice"})
require.NoError(t, err)
assert.Equal(t, "42", userID)
}
func TestResolveMyUserIDReturnsHelpfulErrorWhenGetMeFails(t *testing.T) {
client := fakeClient{
sendRequest: func(options api.RequestOptions) (json.RawMessage, error) {
require.Equal(t, "/2/users/me?user.fields=created_at,description,public_metrics,verified,verified_type,subscription_type,profile_image_url", options.Endpoint)
return nil, fmt.Errorf("boom")
},
}
_, err := resolveMyUserID(client, api.RequestOptions{})
require.Error(t, err)
assert.Contains(t, err.Error(), "try --username")
}