github.com/sacloud/libsacloud/v2@v2.32.3/helper/builder/disk/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 disk 16 17 import ( 18 "testing" 19 20 "github.com/sacloud/libsacloud/v2/sacloud/ostype" 21 "github.com/sacloud/libsacloud/v2/sacloud/types" 22 "github.com/stretchr/testify/require" 23 ) 24 25 func TestDiskDirector_Builder(t *testing.T) { 26 cases := []struct { 27 name string 28 in *Director 29 out Builder 30 }{ 31 { 32 name: "blank disk", 33 in: &Director{}, 34 out: &BlankBuilder{}, 35 }, 36 { 37 name: "connect disk", 38 in: &Director{ 39 DiskID: types.ID(1), 40 }, 41 out: &ConnectedDiskBuilder{ 42 ID: types.ID(1), 43 }, 44 }, 45 { 46 name: "from archive", 47 in: &Director{ 48 SourceArchiveID: types.ID(1), 49 }, 50 out: &FromDiskOrArchiveBuilder{ 51 SourceArchiveID: types.ID(1), 52 }, 53 }, 54 { 55 name: "from disk", 56 in: &Director{ 57 SourceDiskID: types.ID(1), 58 }, 59 out: &FromDiskOrArchiveBuilder{ 60 SourceDiskID: types.ID(1), 61 }, 62 }, 63 { 64 name: "unix", 65 in: &Director{ 66 OSType: ostype.CentOS, 67 EditParameter: &EditRequest{ 68 HostName: "example", 69 }, 70 }, 71 out: &FromUnixBuilder{ 72 OSType: ostype.CentOS, 73 EditParameter: &UnixEditRequest{ 74 HostName: "example", 75 }, 76 }, 77 }, 78 { 79 name: "windows", 80 in: &Director{ 81 OSType: ostype.Windows2019, 82 EditParameter: &EditRequest{ 83 IPAddress: "192.2.0.1", 84 }, 85 }, 86 out: &FromWindowsBuilder{ 87 OSType: ostype.Windows2019, 88 EditParameter: &WindowsEditRequest{ 89 IPAddress: "192.2.0.1", 90 }, 91 }, 92 }, 93 } 94 95 for _, tt := range cases { 96 builder := tt.in.Builder() 97 require.Equal(t, tt.out, builder, tt.name) 98 } 99 }