github.com/sacloud/iaas-api-go@v1.12.0/test/ipv6addr_op_test.go (about) 1 // Copyright 2022-2023 The sacloud/iaas-api-go 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 15 package test 16 17 import ( 18 "context" 19 "os" 20 "testing" 21 22 "github.com/sacloud/iaas-api-go" 23 "github.com/sacloud/iaas-api-go/testutil" 24 "github.com/stretchr/testify/assert" 25 ) 26 27 // TestIPv6AddrOp_CRUD . 28 // 29 // Note: IDが特殊(数値でなくIPv6アドレス)なため、CRUDTestCaseを利用しない 30 func TestIPv6AddrOp_CRUD(t *testing.T) { 31 t.Parallel() 32 33 testutil.PreCheckEnvsFunc("SAKURACLOUD_IPV6ADDRESS", "SAKURACLOUD_IPV6HOSTNAME")(t) 34 35 client := iaas.NewIPv6AddrOp(singletonAPICaller()) 36 ip := os.Getenv("SAKURACLOUD_IPV6ADDRESS") 37 hostName := os.Getenv("SAKURACLOUD_IPV6HOSTNAME") 38 39 // create 40 created, err := client.Create(context.Background(), testZone, &iaas.IPv6AddrCreateRequest{ 41 IPv6Addr: ip, 42 HostName: hostName, 43 }) 44 assert.NoError(t, err) 45 assert.Equal(t, created.IPv6Addr, ip) 46 assert.Equal(t, created.HostName, hostName) 47 48 // read 49 read, err := client.Read(context.Background(), testZone, ip) 50 assert.NoError(t, err) 51 assert.Equal(t, read.IPv6Addr, ip) 52 assert.Equal(t, read.HostName, hostName) 53 54 // update 55 updated, err := client.Update(context.Background(), testZone, ip, &iaas.IPv6AddrUpdateRequest{ 56 HostName: "", 57 }) 58 assert.NoError(t, err) 59 assert.Equal(t, updated.IPv6Addr, ip) 60 assert.Equal(t, updated.HostName, "") 61 62 // delete 63 err = client.Delete(context.Background(), testZone, ip) 64 assert.NoError(t, err) 65 }