File: lke_clusters_acl_test.go

package info (click to toggle)
golang-github-linode-linodego 1.55.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,112 kB
  • sloc: makefile: 96; sh: 52; python: 24
file content (72 lines) | stat: -rw-r--r-- 1,970 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package integration

import (
	"context"
	"testing"

	"github.com/linode/linodego"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestLKECluster_withACL(t *testing.T) {
	valueTrue := true

	client, cluster, teardown, err := setupLKECluster(
		t,
		[]clusterModifier{
			func(options *linodego.LKEClusterCreateOptions) {
				options.ControlPlane = &linodego.LKEClusterControlPlaneOptions{
					ACL: &linodego.LKEClusterControlPlaneACLOptions{
						Enabled: &valueTrue,
						Addresses: &linodego.LKEClusterControlPlaneACLAddressesOptions{
							IPv4: &[]string{"10.0.0.1/32"},
							IPv6: &[]string{"1234::5678"},
						},
					},
				}
			},
		},
		"fixtures/TestLKECluster_withACL",
	)
	require.NoError(t, err)
	defer teardown()

	acl, err := client.GetLKEClusterControlPlaneACL(context.Background(), cluster.ID)
	assert.NoError(t, err)

	require.Equal(t, true, acl.ACL.Enabled)
	require.Equal(t, "10.0.0.1/32", acl.ACL.Addresses.IPv4[0])
	require.Equal(t, "1234::5678/128", acl.ACL.Addresses.IPv6[0])

	testRevisionID := "test-revision-id"

	acl, err = client.UpdateLKEClusterControlPlaneACL(
		context.Background(),
		cluster.ID,
		linodego.LKEClusterControlPlaneACLUpdateOptions{
			ACL: linodego.LKEClusterControlPlaneACLOptions{
				Enabled: &valueTrue,
				Addresses: &linodego.LKEClusterControlPlaneACLAddressesOptions{
					IPv4: &[]string{"10.0.0.2/32"},
					IPv6: &[]string{},
				},
				RevisionID: testRevisionID,
			},
		},
	)
	require.NoError(t, err)

	require.Equal(t, true, acl.ACL.Enabled)
	require.Equal(t, "10.0.0.2/32", acl.ACL.Addresses.IPv4[0])
	require.Equal(t, 0, len(acl.ACL.Addresses.IPv6))
	assert.Equal(t, testRevisionID, acl.ACL.RevisionID)

	err = client.DeleteLKEClusterControlPlaneACL(context.Background(), cluster.ID)
	require.NoError(t, err)

	acl, err = client.GetLKEClusterControlPlaneACL(context.Background(), cluster.ID)
	assert.NoError(t, err)

	assert.Equal(t, false, acl.ACL.Enabled)
}