@@ -2,6 +2,7 @@ package unit
22
33import (
44 "context"
5+ "encoding/json"
56 "fmt"
67 "strconv"
78 "testing"
@@ -44,7 +45,7 @@ func TestInstances_List(t *testing.T) {
4445 require .NotNil (t , linode .PlacementGroup .MigratingTo )
4546 assert .Equal (t , 2468 , * linode .PlacementGroup .MigratingTo )
4647 assert .Equal (t , "linode/migrate" , linode .MaintenancePolicy )
47- if len (linode .Alerts .SystemAlerts ) > 2 {
48+ if len (linode .Alerts .SystemAlerts ) >= 2 {
4849 assert .Equal (t , 123 , linode .Alerts .SystemAlerts [0 ])
4950 assert .Equal (t , 456 , linode .Alerts .SystemAlerts [1 ])
5051 }
@@ -84,7 +85,7 @@ func TestInstance_Get(t *testing.T) {
8485 assert .Equal (t , "linode/migrate" , instance .MaintenancePolicy )
8586 require .NotNil (t , instance .PlacementGroup .MigratingTo )
8687 assert .Equal (t , 2468 , * instance .PlacementGroup .MigratingTo )
87- if len (instance .Alerts .SystemAlerts ) > 2 {
88+ if len (instance .Alerts .SystemAlerts ) >= 2 {
8889 assert .Equal (t , 123 , instance .Alerts .SystemAlerts [0 ])
8990 assert .Equal (t , 456 , instance .Alerts .SystemAlerts [1 ])
9091 }
@@ -206,7 +207,7 @@ func TestInstance_Create(t *testing.T) {
206207 assert .NoError (t , err )
207208 assert .Equal (t , "new-instance" , instance .Label )
208209 assert .Equal (t , "linode/migrate" , instance .MaintenancePolicy )
209- if len (instance .Alerts .SystemAlerts ) > 2 {
210+ if len (instance .Alerts .SystemAlerts ) >= 2 {
210211 assert .Equal (t , 123 , instance .Alerts .SystemAlerts [0 ])
211212 assert .Equal (t , 456 , instance .Alerts .SystemAlerts [1 ])
212213 }
@@ -238,7 +239,7 @@ func TestInstance_Update(t *testing.T) {
238239 assert .NoError (t , err )
239240 assert .Equal (t , "updated-instance" , instance .Label )
240241 assert .Equal (t , "linode/power_off_on" , instance .MaintenancePolicy )
241- if len (instance .Alerts .SystemAlerts ) > 2 {
242+ if len (instance .Alerts .SystemAlerts ) >= 2 {
242243 assert .Equal (t , 123 , instance .Alerts .SystemAlerts [0 ])
243244 assert .Equal (t , 456 , instance .Alerts .SystemAlerts [1 ])
244245 }
@@ -304,7 +305,7 @@ func TestInstance_Clone(t *testing.T) {
304305 assert .NoError (t , err )
305306 assert .Equal (t , "cloned-instance" , instance .Label )
306307 assert .Equal (t , "linode/migrate" , instance .MaintenancePolicy )
307- if len (instance .Alerts .SystemAlerts ) > 2 {
308+ if len (instance .Alerts .SystemAlerts ) >= 2 {
308309 assert .Equal (t , 123 , instance .Alerts .SystemAlerts [0 ])
309310 assert .Equal (t , 456 , instance .Alerts .SystemAlerts [1 ])
310311 }
@@ -359,3 +360,21 @@ func TestInstance_Rebuild(t *testing.T) {
359360 assert .NoError (t , err )
360361 assert .Equal (t , "linode/ubuntu22.04" , instance .Image )
361362}
363+
364+ func TestInstanceACLPAlerts_MarshalEmptyList (t * testing.T ) {
365+ opts := linodego.InstanceACLPAlertsOptions {
366+ SystemAlerts : []int {},
367+ UserAlerts : []int {},
368+ }
369+
370+ buf , err := json .Marshal (opts )
371+ if err != nil {
372+ t .Fatalf ("failed to marshal options: %v" , err )
373+ }
374+
375+ // The goal of omitzero here is to ensure empty list is present
376+ expected := `{"system_alerts":[],"user_alerts":[]}`
377+ if string (buf ) != expected {
378+ t .Errorf ("expected JSON %s, got %s" , expected , string (buf ))
379+ }
380+ }
0 commit comments