-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient_test.go
54 lines (44 loc) · 1.21 KB
/
client_test.go
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
// Copyright (c) David Bond, Tailscale Inc, & Contributors
// SPDX-License-Identifier: MIT
package tailscale
import (
_ "embed"
"io"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestErrorData(t *testing.T) {
t.Parallel()
t.Run("It should return the data element from a valid error", func(t *testing.T) {
expected := APIError{
Data: []APIErrorData{
{
User: "[email protected]",
Errors: []string{
"address \"[email protected]:400\": want: Accept, got: Drop",
},
},
},
}
actual := ErrorData(expected)
assert.EqualValues(t, expected.Data, actual)
})
t.Run("It should return an empty slice for any other error", func(t *testing.T) {
assert.Empty(t, ErrorData(io.EOF))
})
}
func Test_BuildTailnetURL(t *testing.T) {
t.Parallel()
base, err := url.Parse("http://example.com")
require.NoError(t, err)
c := &Client{
BaseURL: base,
Tailnet: "tn/with/slashes",
}
actual := c.buildTailnetURL("component/with/slashes")
expected, err := url.Parse("http://example.com/api/v2/tailnet/tn%2Fwith%2Fslashes/component%2Fwith%2Fslashes")
require.NoError(t, err)
assert.EqualValues(t, expected.String(), actual.String())
}