File: instance_firewalls_test.go

package info (click to toggle)
golang-github-linode-linodego 1.47.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 10,032 kB
  • sloc: makefile: 95; sh: 52; python: 24
file content (49 lines) | stat: -rw-r--r-- 1,492 bytes parent folder | download
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
package integration

import (
	"context"
	"testing"

	"github.com/linode/linodego"
)

func TestInstanceFirewalls_List(t *testing.T) {
	client, instance, _, teardown, err := setupInstanceFirewall(t, []firewallModifier{
		func(createOpts *linodego.FirewallCreateOptions) {
			createOpts.Label = "linodego-fw-ins-test"
		},
	}, "fixtures/TestInstanceFirewalls_List")
	if err != nil {
		t.Error(err)
	}
	defer teardown()

	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, func(), error) {
	t.Helper()
	client, instance, instanceTeardown, err := setupInstance(t, fixturesYaml, false,
		func(client *linodego.Client, opts *linodego.InstanceCreateOptions) {
			opts.Label = "linodego-fw-inst-test"
		})
	device := linodego.DevicesCreationOptions{Linodes: []int{instance.ID}}
	firewallModifiers = append(firewallModifiers,
		func(createOpts *linodego.FirewallCreateOptions) {
			createOpts.Devices = device
		})
	firewall, firewallTeardown, err := createFirewall(t, client, firewallModifiers...)

	teardown := func() {
		firewallTeardown()
		instanceTeardown()
	}
	return client, instance, firewall, teardown, err
}