1// Copyright 2016-2020 The Libsacloud Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package sacloud
16
17import (
18	"encoding/json"
19	"testing"
20
21	"github.com/stretchr/testify/assert"
22)
23
24var (
25	testIPv6NetJSON = `
26	{
27		"CreatedAt": "2016-10-04T13:02:51+09:00",
28		"ID": 999,
29		"IPv6Prefix": "2001:e42:100:100::",
30		"IPv6PrefixTail": "2001:e42:100:100::",
31		"IPv6PrefixLen": 64,
32		"IPv6Table": {
33			"ID": 1
34		},
35		"NamedIPv6AddrCount": 1,
36		"ServiceClass": "cloud/global-ipaddress-v6/64",
37		"ServiceID": 123456789012,
38		"Switch": {
39			"Availability": "available",
40			"ID": 123456789012,
41			"Internet": {
42			    "BandWidthMbps": 100,
43			    "ID": 123456789012,
44			    "Name": "libsacloud_test_vpc_and_internet",
45			    "Scope": "user",
46			    "ServiceClass": "cloud/internet/router/100m"
47			},
48			"Name": "libsacloud_test_vpc_and_internet"
49		}
50        }
51
52	`
53	testIPv6AddrJSON = `
54	{
55            "HostName": "testhost.libsacloud.com",
56            "IPv6Addr": "2001:e42:100:100::5",
57            "IPv6Net": {
58                "ID": 330,
59                "Switch": {
60                    "ID": 123456789012
61                }
62            },
63            "Interface": null
64        }
65
66	`
67)
68
69func TestMarshalIPv6JSON(t *testing.T) {
70	var net IPv6Net
71	err := json.Unmarshal([]byte(testIPv6NetJSON), &net)
72
73	assert.NoError(t, err)
74	assert.NotEmpty(t, net.IPv6Prefix)
75
76	var addr IPv6Addr
77	err = json.Unmarshal([]byte(testIPv6AddrJSON), &addr)
78
79	assert.NoError(t, err)
80	assert.NotEmpty(t, addr.IPv6Addr)
81
82}
83