From 599870dda98bd771609845ddd050a61a09eb6669 Mon Sep 17 00:00:00 2001 From: Ye Chen Date: Mon, 6 Apr 2026 11:14:51 -0400 Subject: [PATCH 1/7] rm omitempty --- instances.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/instances.go b/instances.go index 0e01e98b5..154af61ef 100644 --- a/instances.go +++ b/instances.go @@ -102,8 +102,8 @@ type InstanceAlert struct { NetworkIn int `json:"network_in"` NetworkOut int `json:"network_out"` TransferQuota int `json:"transfer_quota"` - SystemAlerts []int `json:"system_alerts,omitempty"` - UserAlerts []int `json:"user_alerts,omitempty"` + SystemAlerts []int `json:"system_alerts"` + UserAlerts []int `json:"user_alerts"` } // InstanceBackup represents backup settings for an instance @@ -235,8 +235,8 @@ type InstanceCreateOptions struct { // InstanceACLPAlertsOptions represents ACLP alerts options for instance creation and cloning. type InstanceACLPAlertsOptions struct { - SystemAlerts []int `json:"system_alerts,omitempty"` - UserAlerts []int `json:"user_alerts,omitempty"` + SystemAlerts []int `json:"system_alerts"` + UserAlerts []int `json:"user_alerts"` } // InstanceCreatePlacementGroupOptions represents the placement group From 2352c1b071895ff3ce35fb1003bfd163a5a6093d Mon Sep 17 00:00:00 2001 From: Ye Chen Date: Mon, 6 Apr 2026 12:59:56 -0400 Subject: [PATCH 2/7] use pointer --- instances.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/instances.go b/instances.go index 154af61ef..ae9b986b2 100644 --- a/instances.go +++ b/instances.go @@ -97,13 +97,13 @@ type InstanceSpec struct { // InstanceAlert represents a metric alert type InstanceAlert struct { - CPU int `json:"cpu"` - IO int `json:"io"` - NetworkIn int `json:"network_in"` - NetworkOut int `json:"network_out"` - TransferQuota int `json:"transfer_quota"` - SystemAlerts []int `json:"system_alerts"` - UserAlerts []int `json:"user_alerts"` + CPU int `json:"cpu"` + IO int `json:"io"` + NetworkIn int `json:"network_in"` + NetworkOut int `json:"network_out"` + TransferQuota int `json:"transfer_quota"` + SystemAlerts *[]int `json:"system_alerts,omitempty"` + UserAlerts *[]int `json:"user_alerts,omitempty"` } // InstanceBackup represents backup settings for an instance @@ -235,8 +235,8 @@ type InstanceCreateOptions struct { // InstanceACLPAlertsOptions represents ACLP alerts options for instance creation and cloning. type InstanceACLPAlertsOptions struct { - SystemAlerts []int `json:"system_alerts"` - UserAlerts []int `json:"user_alerts"` + SystemAlerts *[]int `json:"system_alerts,omitempty"` + UserAlerts *[]int `json:"user_alerts,omitempty"` } // InstanceCreatePlacementGroupOptions represents the placement group From ab5fb315b14d015f4bdbab5ff1b153f9956f3d45 Mon Sep 17 00:00:00 2001 From: Ye Chen Date: Mon, 6 Apr 2026 13:07:32 -0400 Subject: [PATCH 3/7] update unit test --- test/unit/instance_test.go | 92 +++++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 31 deletions(-) diff --git a/test/unit/instance_test.go b/test/unit/instance_test.go index f4e12eca7..37a070ed1 100644 --- a/test/unit/instance_test.go +++ b/test/unit/instance_test.go @@ -44,12 +44,18 @@ func TestInstances_List(t *testing.T) { require.NotNil(t, linode.PlacementGroup.MigratingTo) assert.Equal(t, 2468, *linode.PlacementGroup.MigratingTo) assert.Equal(t, "linode/migrate", linode.MaintenancePolicy) - if len(linode.Alerts.SystemAlerts) > 2 { - assert.Equal(t, 123, linode.Alerts.SystemAlerts[0]) - assert.Equal(t, 456, linode.Alerts.SystemAlerts[1]) + if linode.Alerts.SystemAlerts != nil { + systemAlerts := *linode.Alerts.SystemAlerts + if len(systemAlerts) > 2 { + assert.Equal(t, 123, systemAlerts[0]) + assert.Equal(t, 456, systemAlerts[1]) + } } - if len(linode.Alerts.UserAlerts) > 0 { - assert.Equal(t, 555, linode.Alerts.UserAlerts[0]) + if linode.Alerts.UserAlerts != nil { + userAlerts := *linode.Alerts.UserAlerts + if len(userAlerts) > 0 { + assert.Equal(t, 555, userAlerts[0]) + } } } @@ -84,12 +90,18 @@ func TestInstance_Get(t *testing.T) { assert.Equal(t, "linode/migrate", instance.MaintenancePolicy) require.NotNil(t, instance.PlacementGroup.MigratingTo) assert.Equal(t, 2468, *instance.PlacementGroup.MigratingTo) - if len(instance.Alerts.SystemAlerts) > 2 { - assert.Equal(t, 123, instance.Alerts.SystemAlerts[0]) - assert.Equal(t, 456, instance.Alerts.SystemAlerts[1]) + if instance.Alerts.SystemAlerts != nil { + systemAlerts := *instance.Alerts.SystemAlerts + if len(*instance.Alerts.SystemAlerts) > 2 { + assert.Equal(t, 123, systemAlerts[0]) + assert.Equal(t, 456, systemAlerts[1]) + } } - if len(instance.Alerts.UserAlerts) > 0 { - assert.Equal(t, 555, instance.Alerts.UserAlerts[0]) + if instance.Alerts.UserAlerts != nil { + userAlerts := *instance.Alerts.UserAlerts + if len(userAlerts) > 0 { + assert.Equal(t, 555, userAlerts[0]) + } } } @@ -195,8 +207,8 @@ func TestInstance_Create(t *testing.T) { RootPass: "securepassword", MaintenancePolicy: linodego.Pointer("linode/migrate"), Alerts: &linodego.InstanceACLPAlertsOptions{ - SystemAlerts: []int{123, 456}, - UserAlerts: []int{555}, + SystemAlerts: &[]int{123, 456}, + UserAlerts: &[]int{555}, }, } @@ -206,12 +218,18 @@ func TestInstance_Create(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "new-instance", instance.Label) assert.Equal(t, "linode/migrate", instance.MaintenancePolicy) - if len(instance.Alerts.SystemAlerts) > 2 { - assert.Equal(t, 123, instance.Alerts.SystemAlerts[0]) - assert.Equal(t, 456, instance.Alerts.SystemAlerts[1]) + if instance.Alerts.SystemAlerts != nil { + systemAlerts := *instance.Alerts.SystemAlerts + if len(*instance.Alerts.SystemAlerts) > 2 { + assert.Equal(t, 123, systemAlerts[0]) + assert.Equal(t, 456, systemAlerts[1]) + } } - if len(instance.Alerts.UserAlerts) > 0 { - assert.Equal(t, 555, instance.Alerts.UserAlerts[0]) + if instance.Alerts.UserAlerts != nil { + userAlerts := *instance.Alerts.UserAlerts + if len(userAlerts) > 0 { + assert.Equal(t, 555, userAlerts[0]) + } } } @@ -227,8 +245,8 @@ func TestInstance_Update(t *testing.T) { Label: "updated-instance", MaintenancePolicy: linodego.Pointer("linode/power_off_on"), Alerts: &linodego.InstanceAlert{ - SystemAlerts: []int{123, 456}, - UserAlerts: []int{555}, + SystemAlerts: &[]int{123, 456}, + UserAlerts: &[]int{555}, }, } @@ -238,12 +256,18 @@ func TestInstance_Update(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "updated-instance", instance.Label) assert.Equal(t, "linode/power_off_on", instance.MaintenancePolicy) - if len(instance.Alerts.SystemAlerts) > 2 { - assert.Equal(t, 123, instance.Alerts.SystemAlerts[0]) - assert.Equal(t, 456, instance.Alerts.SystemAlerts[1]) + if instance.Alerts.SystemAlerts != nil { + systemAlerts := *instance.Alerts.SystemAlerts + if len(*instance.Alerts.SystemAlerts) > 2 { + assert.Equal(t, 123, systemAlerts[0]) + assert.Equal(t, 456, systemAlerts[1]) + } } - if len(instance.Alerts.UserAlerts) > 0 { - assert.Equal(t, 555, instance.Alerts.UserAlerts[0]) + if instance.Alerts.UserAlerts != nil { + userAlerts := *instance.Alerts.UserAlerts + if len(userAlerts) > 0 { + assert.Equal(t, 555, userAlerts[0]) + } } } @@ -293,8 +317,8 @@ func TestInstance_Clone(t *testing.T) { Type: "g6-standard-1", Label: "cloned-instance", Alerts: &linodego.InstanceACLPAlertsOptions{ - SystemAlerts: []int{123, 456}, - UserAlerts: []int{555}, + SystemAlerts: &[]int{123, 456}, + UserAlerts: &[]int{555}, }, } @@ -304,12 +328,18 @@ func TestInstance_Clone(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "cloned-instance", instance.Label) assert.Equal(t, "linode/migrate", instance.MaintenancePolicy) - if len(instance.Alerts.SystemAlerts) > 2 { - assert.Equal(t, 123, instance.Alerts.SystemAlerts[0]) - assert.Equal(t, 456, instance.Alerts.SystemAlerts[1]) + if instance.Alerts.SystemAlerts != nil { + systemAlerts := *instance.Alerts.SystemAlerts + if len(*instance.Alerts.SystemAlerts) > 2 { + assert.Equal(t, 123, systemAlerts[0]) + assert.Equal(t, 456, systemAlerts[1]) + } } - if len(instance.Alerts.UserAlerts) > 0 { - assert.Equal(t, 555, instance.Alerts.UserAlerts[0]) + if instance.Alerts.UserAlerts != nil { + userAlerts := *instance.Alerts.UserAlerts + if len(userAlerts) > 0 { + assert.Equal(t, 555, userAlerts[0]) + } } } From 54d0303e6d80a16edce6ef472d503a51b1751aad Mon Sep 17 00:00:00 2001 From: Ye Chen Date: Mon, 6 Apr 2026 13:39:48 -0400 Subject: [PATCH 4/7] misc --- test/unit/instance_test.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/unit/instance_test.go b/test/unit/instance_test.go index 37a070ed1..e520f0121 100644 --- a/test/unit/instance_test.go +++ b/test/unit/instance_test.go @@ -46,7 +46,7 @@ func TestInstances_List(t *testing.T) { assert.Equal(t, "linode/migrate", linode.MaintenancePolicy) if linode.Alerts.SystemAlerts != nil { systemAlerts := *linode.Alerts.SystemAlerts - if len(systemAlerts) > 2 { + if len(systemAlerts) >= 2 { assert.Equal(t, 123, systemAlerts[0]) assert.Equal(t, 456, systemAlerts[1]) } @@ -92,7 +92,7 @@ func TestInstance_Get(t *testing.T) { assert.Equal(t, 2468, *instance.PlacementGroup.MigratingTo) if instance.Alerts.SystemAlerts != nil { systemAlerts := *instance.Alerts.SystemAlerts - if len(*instance.Alerts.SystemAlerts) > 2 { + if len(systemAlerts) >= 2 { assert.Equal(t, 123, systemAlerts[0]) assert.Equal(t, 456, systemAlerts[1]) } @@ -207,8 +207,8 @@ func TestInstance_Create(t *testing.T) { RootPass: "securepassword", MaintenancePolicy: linodego.Pointer("linode/migrate"), Alerts: &linodego.InstanceACLPAlertsOptions{ - SystemAlerts: &[]int{123, 456}, - UserAlerts: &[]int{555}, + SystemAlerts: linodego.Pointer([]int{123, 456}), + UserAlerts: linodego.Pointer([]int{555}), }, } @@ -220,7 +220,7 @@ func TestInstance_Create(t *testing.T) { assert.Equal(t, "linode/migrate", instance.MaintenancePolicy) if instance.Alerts.SystemAlerts != nil { systemAlerts := *instance.Alerts.SystemAlerts - if len(*instance.Alerts.SystemAlerts) > 2 { + if len(systemAlerts) >= 2 { assert.Equal(t, 123, systemAlerts[0]) assert.Equal(t, 456, systemAlerts[1]) } @@ -245,8 +245,8 @@ func TestInstance_Update(t *testing.T) { Label: "updated-instance", MaintenancePolicy: linodego.Pointer("linode/power_off_on"), Alerts: &linodego.InstanceAlert{ - SystemAlerts: &[]int{123, 456}, - UserAlerts: &[]int{555}, + SystemAlerts: linodego.Pointer([]int{123, 456}), + UserAlerts: linodego.Pointer([]int{555}), }, } @@ -258,7 +258,7 @@ func TestInstance_Update(t *testing.T) { assert.Equal(t, "linode/power_off_on", instance.MaintenancePolicy) if instance.Alerts.SystemAlerts != nil { systemAlerts := *instance.Alerts.SystemAlerts - if len(*instance.Alerts.SystemAlerts) > 2 { + if len(systemAlerts) >= 2 { assert.Equal(t, 123, systemAlerts[0]) assert.Equal(t, 456, systemAlerts[1]) } @@ -317,8 +317,8 @@ func TestInstance_Clone(t *testing.T) { Type: "g6-standard-1", Label: "cloned-instance", Alerts: &linodego.InstanceACLPAlertsOptions{ - SystemAlerts: &[]int{123, 456}, - UserAlerts: &[]int{555}, + SystemAlerts: linodego.Pointer([]int{123, 456}), + UserAlerts: linodego.Pointer([]int{555}), }, } @@ -330,7 +330,7 @@ func TestInstance_Clone(t *testing.T) { assert.Equal(t, "linode/migrate", instance.MaintenancePolicy) if instance.Alerts.SystemAlerts != nil { systemAlerts := *instance.Alerts.SystemAlerts - if len(*instance.Alerts.SystemAlerts) > 2 { + if len(systemAlerts) >= 2 { assert.Equal(t, 123, systemAlerts[0]) assert.Equal(t, 456, systemAlerts[1]) } From af4eaeb0c745b03e899af8c9ce65ed6cb7149bcb Mon Sep 17 00:00:00 2001 From: Ye Chen Date: Mon, 6 Apr 2026 15:17:06 -0400 Subject: [PATCH 5/7] use omitzero --- instances.go | 18 ++++---- test/unit/instance_test.go | 92 +++++++++++++------------------------- 2 files changed, 40 insertions(+), 70 deletions(-) diff --git a/instances.go b/instances.go index 375dddee9..d309d5f8c 100644 --- a/instances.go +++ b/instances.go @@ -95,13 +95,13 @@ type InstanceSpec struct { // InstanceAlert represents a metric alert type InstanceAlert struct { - CPU int `json:"cpu"` - IO int `json:"io"` - NetworkIn int `json:"network_in"` - NetworkOut int `json:"network_out"` - TransferQuota int `json:"transfer_quota"` - SystemAlerts *[]int `json:"system_alerts,omitempty"` - UserAlerts *[]int `json:"user_alerts,omitempty"` + CPU int `json:"cpu"` + IO int `json:"io"` + NetworkIn int `json:"network_in"` + NetworkOut int `json:"network_out"` + TransferQuota int `json:"transfer_quota"` + SystemAlerts []int `json:"system_alerts,omitzero"` + UserAlerts []int `json:"user_alerts,omitzero"` } // InstanceBackup represents backup settings for an instance @@ -230,8 +230,8 @@ type InstanceCreateOptions struct { // InstanceACLPAlertsOptions represents ACLP alerts options for instance creation and cloning. type InstanceACLPAlertsOptions struct { - SystemAlerts *[]int `json:"system_alerts,omitempty"` - UserAlerts *[]int `json:"user_alerts,omitempty"` + SystemAlerts []int `json:"system_alerts,omitzero"` + UserAlerts []int `json:"user_alerts,omitzero"` } // InstanceCreatePlacementGroupOptions represents the placement group diff --git a/test/unit/instance_test.go b/test/unit/instance_test.go index e520f0121..040095b9e 100644 --- a/test/unit/instance_test.go +++ b/test/unit/instance_test.go @@ -44,18 +44,12 @@ func TestInstances_List(t *testing.T) { require.NotNil(t, linode.PlacementGroup.MigratingTo) assert.Equal(t, 2468, *linode.PlacementGroup.MigratingTo) assert.Equal(t, "linode/migrate", linode.MaintenancePolicy) - if linode.Alerts.SystemAlerts != nil { - systemAlerts := *linode.Alerts.SystemAlerts - if len(systemAlerts) >= 2 { - assert.Equal(t, 123, systemAlerts[0]) - assert.Equal(t, 456, systemAlerts[1]) - } + if len(linode.Alerts.SystemAlerts) >= 2 { + assert.Equal(t, 123, linode.Alerts.SystemAlerts[0]) + assert.Equal(t, 456, linode.Alerts.SystemAlerts[1]) } - if linode.Alerts.UserAlerts != nil { - userAlerts := *linode.Alerts.UserAlerts - if len(userAlerts) > 0 { - assert.Equal(t, 555, userAlerts[0]) - } + if len(linode.Alerts.UserAlerts) > 0 { + assert.Equal(t, 555, linode.Alerts.UserAlerts[0]) } } @@ -90,18 +84,12 @@ func TestInstance_Get(t *testing.T) { assert.Equal(t, "linode/migrate", instance.MaintenancePolicy) require.NotNil(t, instance.PlacementGroup.MigratingTo) assert.Equal(t, 2468, *instance.PlacementGroup.MigratingTo) - if instance.Alerts.SystemAlerts != nil { - systemAlerts := *instance.Alerts.SystemAlerts - if len(systemAlerts) >= 2 { - assert.Equal(t, 123, systemAlerts[0]) - assert.Equal(t, 456, systemAlerts[1]) - } + if len(instance.Alerts.SystemAlerts) >= 2 { + assert.Equal(t, 123, instance.Alerts.SystemAlerts[0]) + assert.Equal(t, 456, instance.Alerts.SystemAlerts[1]) } - if instance.Alerts.UserAlerts != nil { - userAlerts := *instance.Alerts.UserAlerts - if len(userAlerts) > 0 { - assert.Equal(t, 555, userAlerts[0]) - } + if len(instance.Alerts.UserAlerts) > 0 { + assert.Equal(t, 555, instance.Alerts.UserAlerts[0]) } } @@ -207,8 +195,8 @@ func TestInstance_Create(t *testing.T) { RootPass: "securepassword", MaintenancePolicy: linodego.Pointer("linode/migrate"), Alerts: &linodego.InstanceACLPAlertsOptions{ - SystemAlerts: linodego.Pointer([]int{123, 456}), - UserAlerts: linodego.Pointer([]int{555}), + SystemAlerts: []int{123, 456}, + UserAlerts: []int{555}, }, } @@ -218,18 +206,12 @@ func TestInstance_Create(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "new-instance", instance.Label) assert.Equal(t, "linode/migrate", instance.MaintenancePolicy) - if instance.Alerts.SystemAlerts != nil { - systemAlerts := *instance.Alerts.SystemAlerts - if len(systemAlerts) >= 2 { - assert.Equal(t, 123, systemAlerts[0]) - assert.Equal(t, 456, systemAlerts[1]) - } + if len(instance.Alerts.SystemAlerts) >= 2 { + assert.Equal(t, 123, instance.Alerts.SystemAlerts[0]) + assert.Equal(t, 456, instance.Alerts.SystemAlerts[1]) } - if instance.Alerts.UserAlerts != nil { - userAlerts := *instance.Alerts.UserAlerts - if len(userAlerts) > 0 { - assert.Equal(t, 555, userAlerts[0]) - } + if len(instance.Alerts.UserAlerts) > 0 { + assert.Equal(t, 555, instance.Alerts.UserAlerts[0]) } } @@ -245,8 +227,8 @@ func TestInstance_Update(t *testing.T) { Label: "updated-instance", MaintenancePolicy: linodego.Pointer("linode/power_off_on"), Alerts: &linodego.InstanceAlert{ - SystemAlerts: linodego.Pointer([]int{123, 456}), - UserAlerts: linodego.Pointer([]int{555}), + SystemAlerts: []int{123, 456}, + UserAlerts: []int{555}, }, } @@ -256,18 +238,12 @@ func TestInstance_Update(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "updated-instance", instance.Label) assert.Equal(t, "linode/power_off_on", instance.MaintenancePolicy) - if instance.Alerts.SystemAlerts != nil { - systemAlerts := *instance.Alerts.SystemAlerts - if len(systemAlerts) >= 2 { - assert.Equal(t, 123, systemAlerts[0]) - assert.Equal(t, 456, systemAlerts[1]) - } + if len(instance.Alerts.SystemAlerts) >= 2 { + assert.Equal(t, 123, instance.Alerts.SystemAlerts[0]) + assert.Equal(t, 456, instance.Alerts.SystemAlerts[1]) } - if instance.Alerts.UserAlerts != nil { - userAlerts := *instance.Alerts.UserAlerts - if len(userAlerts) > 0 { - assert.Equal(t, 555, userAlerts[0]) - } + if len(instance.Alerts.UserAlerts) > 0 { + assert.Equal(t, 555, instance.Alerts.UserAlerts[0]) } } @@ -317,8 +293,8 @@ func TestInstance_Clone(t *testing.T) { Type: "g6-standard-1", Label: "cloned-instance", Alerts: &linodego.InstanceACLPAlertsOptions{ - SystemAlerts: linodego.Pointer([]int{123, 456}), - UserAlerts: linodego.Pointer([]int{555}), + SystemAlerts: []int{123, 456}, + UserAlerts: []int{555}, }, } @@ -328,18 +304,12 @@ func TestInstance_Clone(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "cloned-instance", instance.Label) assert.Equal(t, "linode/migrate", instance.MaintenancePolicy) - if instance.Alerts.SystemAlerts != nil { - systemAlerts := *instance.Alerts.SystemAlerts - if len(systemAlerts) >= 2 { - assert.Equal(t, 123, systemAlerts[0]) - assert.Equal(t, 456, systemAlerts[1]) - } + if len(instance.Alerts.SystemAlerts) >= 2 { + assert.Equal(t, 123, instance.Alerts.SystemAlerts[0]) + assert.Equal(t, 456, instance.Alerts.SystemAlerts[1]) } - if instance.Alerts.UserAlerts != nil { - userAlerts := *instance.Alerts.UserAlerts - if len(userAlerts) > 0 { - assert.Equal(t, 555, userAlerts[0]) - } + if len(instance.Alerts.UserAlerts) > 0 { + assert.Equal(t, 555, instance.Alerts.UserAlerts[0]) } } From 86e68c2e2577e9ec36e17b03dd1f8c92d07d9d8f Mon Sep 17 00:00:00 2001 From: Ye Chen Date: Mon, 6 Apr 2026 15:22:25 -0400 Subject: [PATCH 6/7] nit --- test/unit/instance_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/instance_test.go b/test/unit/instance_test.go index 040095b9e..44a88b030 100644 --- a/test/unit/instance_test.go +++ b/test/unit/instance_test.go @@ -196,7 +196,7 @@ func TestInstance_Create(t *testing.T) { MaintenancePolicy: linodego.Pointer("linode/migrate"), Alerts: &linodego.InstanceACLPAlertsOptions{ SystemAlerts: []int{123, 456}, - UserAlerts: []int{555}, + UserAlerts: []int{555}, }, } From 00c9ab1fb987a34971c10f9ad2a38f56eb4b8057 Mon Sep 17 00:00:00 2001 From: Ye Chen Date: Fri, 10 Apr 2026 11:16:51 -0400 Subject: [PATCH 7/7] add marshal empty test --- test/unit/instance_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/unit/instance_test.go b/test/unit/instance_test.go index 44a88b030..0017aac44 100644 --- a/test/unit/instance_test.go +++ b/test/unit/instance_test.go @@ -2,6 +2,7 @@ package unit import ( "context" + "encoding/json" "fmt" "strconv" "testing" @@ -359,3 +360,21 @@ func TestInstance_Rebuild(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "linode/ubuntu22.04", instance.Image) } + +func TestInstanceACLPAlerts_MarshalEmptyList(t *testing.T) { + opts := linodego.InstanceACLPAlertsOptions{ + SystemAlerts: []int{}, + UserAlerts: []int{}, + } + + buf, err := json.Marshal(opts) + if err != nil { + t.Fatalf("failed to marshal options: %v", err) + } + + // The goal of omitzero here is to ensure empty list is present + expected := `{"system_alerts":[],"user_alerts":[]}` + if string(buf) != expected { + t.Errorf("expected JSON %s, got %s", expected, string(buf)) + } +}