Skip to content

Commit 4c357f9

Browse files
committed
devices: make LastSeen a pointer
As of [this API release](https://tailscale.com/changelog#2025-10-08), LastSeen is expected to be empty when ConnectedToControl is true. LastSeen is now a pointer to make it clear that his is the case. Updates tailscale/corp#31905 Signed-off-by: Percy Wegmann <[email protected]>
1 parent d0b9e8f commit 4c357f9

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

client_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@ func Test_BuildTailnetURLDefault(t *testing.T) {
6868
require.NoError(t, err)
6969
assert.EqualValues(t, expected.String(), actual.String())
7070
}
71+
72+
func ptrTo[T any](v T) *T {
73+
return &v
74+
}

devices.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ type Device struct {
8484
IsEphemeral bool `json:"isEphemeral"`
8585
IsExternal bool `json:"isExternal"`
8686
ConnectedToControl bool `json:"connectedToControl"`
87-
LastSeen Time `json:"lastSeen"`
87+
LastSeen *Time `json:"lastSeen"` // Will be nil if ConnectedToControl is true.
8888
MachineKey string `json:"machineKey"`
8989
NodeKey string `json:"nodeKey"`
9090
OS string `json:"os"`

devices_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestClient_Devices_Get(t *testing.T) {
5858
Hostname: "test",
5959
IsExternal: false,
6060
ConnectedToControl: false,
61-
LastSeen: Time{time.Date(2022, 3, 9, 20, 3, 42, 0, time.UTC)},
61+
LastSeen: ptrTo(Time{time.Date(2022, 3, 9, 20, 3, 42, 0, time.UTC)}),
6262
MachineKey: "mkey:test",
6363
NodeKey: "nodekey:test",
6464
IsEphemeral: false,
@@ -167,7 +167,7 @@ func TestClient_Devices_List(t *testing.T) {
167167
IsEphemeral: false,
168168
IsExternal: false,
169169
ConnectedToControl: false,
170-
LastSeen: Time{time.Date(2022, 3, 9, 20, 3, 42, 0, time.UTC)},
170+
LastSeen: ptrTo(Time{time.Date(2022, 3, 9, 20, 3, 42, 0, time.UTC)}),
171171
MachineKey: "mkey:test",
172172
NodeKey: "nodekey:test",
173173
OS: "windows",
@@ -242,9 +242,9 @@ func TestDevices_Unmarshal(t *testing.T) {
242242
IsExternal: true,
243243
KeyExpiryDisabled: true,
244244
ConnectedToControl: false,
245-
LastSeen: Time{
245+
LastSeen: ptrTo(Time{
246246
time.Date(2022, 4, 15, 13, 24, 40, 0, time.UTC),
247-
},
247+
}),
248248
MachineKey: "",
249249
Name: "hello.example.com",
250250
NodeKey: "nodekey:30dc3c061ac8b33fdc6d88a4a67b053b01b56930d78cae0cf7a164411d424c0d",
@@ -270,9 +270,9 @@ func TestDevices_Unmarshal(t *testing.T) {
270270
IsExternal: false,
271271
KeyExpiryDisabled: true,
272272
ConnectedToControl: false,
273-
LastSeen: Time{
273+
LastSeen: ptrTo(Time{
274274
time.Date(2022, 4, 15, 13, 25, 21, 0, time.UTC),
275-
},
275+
}),
276276
MachineKey: "mkey:30dc3c061ac8b33fdc6d88a4a67b053b01b56930d78cae0cf7a164411d424c0d",
277277
Name: "foo.example.com",
278278
NodeKey: "nodekey:30dc3c061ac8b33fdc6d88a4a67b053b01b56930d78cae0cf7a164411d424c0d",

0 commit comments

Comments
 (0)