-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #5 This commit adds the `Data` field to the `APIError` type and provides a helper function `ErrorData` to obtain the slice of errors from the response. This will allow us to expose errors in ACL tests. Signed-off-by: David Bond <[email protected]>
- Loading branch information
1 parent
632055c
commit 20449ae
Showing
2 changed files
with
44 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"context" | ||
_ "embed" | ||
"encoding/json" | ||
"io" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
@@ -537,3 +538,27 @@ func TestClient_SetDeviceTags(t *testing.T) { | |
assert.NoError(t, json.Unmarshal(server.Body.Bytes(), &body)) | ||
assert.EqualValues(t, tags, body["tags"]) | ||
} | ||
|
||
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{ | ||
{ | ||
User: "[email protected]", | ||
Errors: []string{ | ||
"address \"[email protected]:400\": want: Accept, got: Drop", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
actual := tailscale.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)) | ||
}) | ||
} |