-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtailnet_settings_test.go
65 lines (55 loc) · 2.17 KB
/
tailnet_settings_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
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) David Bond, Tailscale Inc, & Contributors
// SPDX-License-Identifier: MIT
package tailscale
import (
"context"
"encoding/json"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestClient_TailnetSettings_Get(t *testing.T) {
t.Parallel()
client, server := NewTestHarness(t)
server.ResponseCode = http.StatusOK
expected := TailnetSettings{
DevicesApprovalOn: true,
DevicesAutoUpdatesOn: true,
DevicesKeyDurationDays: 5,
UsersApprovalOn: true,
UsersRoleAllowedToJoinExternalTailnets: RoleAllowedToJoinExternalTailnetsMember,
NetworkFlowLoggingOn: true,
RegionalRoutingOn: true,
PostureIdentityCollectionOn: true,
}
server.ResponseBody = expected
actual, err := client.TailnetSettings().Get(context.Background())
assert.NoError(t, err)
assert.Equal(t, http.MethodGet, server.Method)
assert.Equal(t, "/api/v2/tailnet/example.com/settings", server.Path)
assert.Equal(t, &expected, actual)
}
func TestClient_TailnetSettings_Update(t *testing.T) {
t.Parallel()
client, server := NewTestHarness(t)
server.ResponseCode = http.StatusOK
server.ResponseBody = nil
updateRequest := UpdateTailnetSettingsRequest{
DevicesApprovalOn: PointerTo(true),
DevicesAutoUpdatesOn: PointerTo(true),
DevicesKeyDurationDays: PointerTo(5),
UsersApprovalOn: PointerTo(true),
UsersRoleAllowedToJoinExternalTailnets: PointerTo(RoleAllowedToJoinExternalTailnetsMember),
NetworkFlowLoggingOn: PointerTo(true),
RegionalRoutingOn: PointerTo(true),
PostureIdentityCollectionOn: PointerTo(true),
}
err := client.TailnetSettings().Update(context.Background(), updateRequest)
assert.NoError(t, err)
assert.Equal(t, http.MethodPatch, server.Method)
assert.Equal(t, "/api/v2/tailnet/example.com/settings", server.Path)
var receivedRequest UpdateTailnetSettingsRequest
err = json.Unmarshal(server.Body.Bytes(), &receivedRequest)
assert.NoError(t, err)
assert.EqualValues(t, updateRequest, receivedRequest)
}