File: network_ipv6_pools_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 (71 lines) | stat: -rw-r--r-- 2,343 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
package unit

import (
	"context"
	"testing"

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

func TestIPIPv6Pools_List(t *testing.T) {
	var base ClientBaseCase
	base.SetUp(t)
	defer base.TearDown(t)

	mockResponse := struct {
		Data []linodego.IPv6Range `json:"data"`
	}{
		Data: []linodego.IPv6Range{
			{
				Range:       "2600:3c00::/64",
				Region:      "us-east",
				Prefix:      64,
				RouteTarget: "2600:3c00::1",
				IsBGP:       true,
				Linodes:     []int{12345, 67890},
			},
		},
	}

	base.MockGet("networking/ipv6/pools", mockResponse)

	pools, err := base.Client.ListIPv6Pools(context.Background(), nil)

	assert.NoError(t, err, "Expected no error when listing IPv6 pools")
	assert.NotNil(t, pools, "Expected non-nil IPv6 pools response")
	assert.Len(t, pools, 1, "Expected one IPv6 pool in response")
	assert.Equal(t, "2600:3c00::/64", pools[0].Range, "Expected matching IPv6 range")
	assert.Equal(t, "us-east", pools[0].Region, "Expected matching region")
	assert.Equal(t, 64, pools[0].Prefix, "Expected matching prefix length")
	assert.Equal(t, "2600:3c00::1", pools[0].RouteTarget, "Expected matching route target")
	assert.True(t, pools[0].IsBGP, "Expected IsBGP to be true")
	assert.ElementsMatch(t, []int{12345, 67890}, pools[0].Linodes, "Expected matching Linodes list")
}

func TestIPIPv6Pool_Get(t *testing.T) {
	var base ClientBaseCase
	base.SetUp(t)
	defer base.TearDown(t)

	id := "1"
	mockResponse := linodego.IPv6Range{
		Range:       "2600:3c00::/64",
		Region:      "us-east",
		Prefix:      64,
		RouteTarget: "2600:3c00::1",
		IsBGP:       false,
		Linodes:     []int{54321},
	}
	base.MockGet("networking/ipv6/pools/"+id, mockResponse)

	pool, err := base.Client.GetIPv6Pool(context.Background(), id)
	assert.NoError(t, err, "Expected no error when getting IPv6 pool")
	assert.NotNil(t, pool, "Expected non-nil IPv6 pool response")
	assert.Equal(t, "2600:3c00::/64", pool.Range, "Expected matching IPv6 range")
	assert.Equal(t, "us-east", pool.Region, "Expected matching region")
	assert.Equal(t, 64, pool.Prefix, "Expected matching prefix length")
	assert.Equal(t, "2600:3c00::1", pool.RouteTarget, "Expected matching route target")
	assert.False(t, pool.IsBGP, "Expected IsBGP to be false")
	assert.ElementsMatch(t, []int{54321}, pool.Linodes, "Expected matching Linodes list")
}