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
|
package integration
import (
"context"
"testing"
"github.com/linode/linodego"
)
func TestInstanceFirewalls_List(t *testing.T) {
client, instance, _, err := setupInstanceFirewall(t, []firewallModifier{
func(createOpts *linodego.FirewallCreateOptions) {
createOpts.Label = "linodego-fw-ins-test"
},
}, "fixtures/TestInstanceFirewalls_List")
if err != nil {
t.Error(err)
}
result, err := client.ListInstanceFirewalls(context.Background(), instance.ID, nil)
if err != nil {
t.Errorf("Error listing Firewalls, expected struct, got error %v", err)
}
if len(result) == 0 {
t.Errorf("Expected a list of Firewalls, but got none: %v", err)
}
}
func setupInstanceFirewall(
t *testing.T,
firewallModifiers []firewallModifier,
fixturesYaml string,
) (*linodego.Client, *linodego.Instance, *linodego.Firewall, error) {
t.Helper()
client, firewall, firewallTeardown, err := setupFirewall(t, firewallModifiers, fixturesYaml)
instance, err := createInstance(t, client, false,
func(client *linodego.Client, opts *linodego.InstanceCreateOptions) {
opts.Label = "linodego-fw-inst-test"
opts.FirewallID = firewall.ID
},
)
t.Cleanup(
func() {
if err := client.DeleteInstance(context.Background(), instance.ID); err != nil {
if t != nil {
t.Errorf("failed deleting test Instance: %s", err)
}
}
firewallTeardown()
},
)
return client, instance, firewall, err
}
|