github.com/sacloud/iaas-api-go@v1.12.0/types/archive_share_key_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 types 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/require" 21 ) 22 23 func TestArchiveShareKey(t *testing.T) { 24 cases := []struct { 25 in string 26 zone string 27 id ID 28 token string 29 valid bool 30 }{ 31 { 32 in: "zone:11111:token", 33 zone: "zone", 34 id: StringID("11111"), 35 token: "token", 36 valid: true, 37 }, 38 { 39 in: "zone:11111", 40 zone: "zone", 41 id: StringID("11111"), 42 token: "", 43 valid: false, 44 }, 45 { 46 in: "zone", 47 zone: "zone", 48 id: StringID(""), 49 token: "", 50 valid: false, 51 }, 52 { 53 in: "", 54 zone: "", 55 id: StringID(""), 56 token: "", 57 valid: false, 58 }, 59 } 60 61 for _, tc := range cases { 62 key := ArchiveShareKey(tc.in) 63 require.Equal(t, key.Zone(), tc.zone) 64 require.Equal(t, key.SourceArchiveID(), tc.id) 65 require.Equal(t, key.Token(), tc.token) 66 require.Equal(t, key.ValidFormat(), tc.valid) 67 } 68 }