github.com/sacloud/libsacloud/v2@v2.32.3/helper/builder/archive/director_test.go (about) 1 // Copyright 2016-2022 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 15 package archive 16 17 import ( 18 "bytes" 19 "testing" 20 21 "github.com/stretchr/testify/require" 22 ) 23 24 func TestDirector_Builder(t *testing.T) { 25 dummySource := bytes.NewBufferString("dummy") 26 27 cases := []struct { 28 msg string 29 in *Director 30 out Builder 31 }{ 32 { 33 msg: "BlankBuilder", 34 in: &Director{ 35 Name: "blank", 36 SizeGB: 20, 37 SourceReader: dummySource, 38 }, 39 out: &BlankArchiveBuilder{ 40 Name: "blank", 41 SizeGB: 20, 42 SourceReader: dummySource, 43 }, 44 }, 45 { 46 msg: "FromSharedArchiveBuilder", 47 in: &Director{ 48 Name: "shared", 49 SourceSharedKey: "is1a:0000:xxxx", 50 }, 51 out: &FromSharedArchiveBuilder{ 52 Name: "shared", 53 SourceSharedKey: "is1a:0000:xxxx", 54 }, 55 }, 56 { 57 msg: "TransferArchiveBuilder", 58 in: &Director{ 59 Name: "transfer", 60 SourceArchiveID: 1, 61 SourceArchiveZone: "is1a", 62 }, 63 out: &TransferArchiveBuilder{ 64 Name: "transfer", 65 SourceArchiveID: 1, 66 SourceArchiveZone: "is1a", 67 }, 68 }, 69 { 70 msg: "StandardArchiveBuilder_with_ArchiveID", 71 in: &Director{ 72 Name: "standard-with-archive-id", 73 SourceArchiveID: 1, 74 }, 75 out: &StandardArchiveBuilder{ 76 Name: "standard-with-archive-id", 77 SourceArchiveID: 1, 78 }, 79 }, 80 { 81 msg: "StandardArchiveBuilder_with_DiskID", 82 in: &Director{ 83 Name: "standard-with-disk-id", 84 SourceDiskID: 1, 85 }, 86 out: &StandardArchiveBuilder{ 87 Name: "standard-with-disk-id", 88 SourceDiskID: 1, 89 }, 90 }, 91 } 92 93 for _, tc := range cases { 94 require.EqualValues(t, tc.out, tc.in.Builder(), tc.msg) 95 } 96 }