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
|
package integration
import (
"context"
"encoding/json"
"testing"
"github.com/linode/linodego"
"github.com/stretchr/testify/require"
)
func TestMaintenancePolicies_List(t *testing.T) {
client, fixtureTeardown := createTestClient(t, "fixtures/TestMaintenancePolicies_List")
defer fixtureTeardown()
resp, err := client.R(context.Background()).Get("maintenance/policies")
require.NoError(t, err)
var result map[string]any
err = json.Unmarshal(resp.Body(), &result)
require.NoError(t, err)
dataRaw, ok := result["data"]
require.True(t, ok, "Expected 'data' key in response")
dataJSON, err := json.Marshal(dataRaw)
require.NoError(t, err)
var policies []linodego.MaintenancePolicy
err = json.Unmarshal(dataJSON, &policies)
require.NoError(t, err)
if len(policies) == 0 {
t.Fatal("Expected at least one maintenance policy, got none")
}
for _, policy := range policies {
if policy.Slug == "" {
t.Error("Policy Slug should not be empty")
}
if policy.Label == "" {
t.Error("Policy Label should not be empty")
}
if policy.Type == "" {
t.Error("Policy Type should not be empty")
}
if policy.NotificationPeriodSec <= 0 {
t.Errorf("NotificationPeriodSec should be positive, got %d", policy.NotificationPeriodSec)
}
}
}
|