-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2: correctly URL encode tailnet in buildTailnetURL (#95)
Adds unit test to test URL building. Updates tailscale/corp#21867 Signed-off-by: Percy Wegmann <[email protected]>
- Loading branch information
Showing
2 changed files
with
25 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
package tailscale_test | ||
package tailscale | ||
|
||
import ( | ||
_ "embed" | ||
"io" | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/tailscale/tailscale-client-go/v2" | ||
"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 := tailscale.APIError{ | ||
Data: []tailscale.APIErrorData{ | ||
expected := APIError{ | ||
Data: []APIErrorData{ | ||
{ | ||
User: "[email protected]", | ||
Errors: []string{ | ||
|
@@ -25,11 +25,27 @@ func TestErrorData(t *testing.T) { | |
}, | ||
} | ||
|
||
actual := tailscale.ErrorData(expected) | ||
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, tailscale.ErrorData(io.EOF)) | ||
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()) | ||
} |