@@ -7,6 +7,7 @@ package provider
77import (
88 "context"
99 "fmt"
10+ "reflect"
1011 "testing"
1112 "time"
1213
@@ -382,13 +383,13 @@ func TestAccCloudResourceInstance_nic(t *testing.T) {
382383data "oxide_project" "{{.SupportBlockName}}" {
383384 name = "tf-acc-test"
384385}
385-
386+
386387data "oxide_vpc_subnet" "{{.SubnetBlockName}}" {
387388 project_name = data.oxide_project.{{.SupportBlockName}}.name
388389 vpc_name = "default"
389390 name = "default"
390391}
391-
392+
392393resource "oxide_instance" "{{.BlockName}}" {
393394 project_id = data.oxide_project.{{.SupportBlockName}}.id
394395 description = "a test instance"
@@ -412,7 +413,7 @@ resource "oxide_instance" "{{.BlockName}}" {
412413data "oxide_project" "{{.SupportBlockName}}" {
413414 name = "tf-acc-test"
414415}
415-
416+
416417resource "oxide_instance" "{{.BlockName}}" {
417418 project_id = data.oxide_project.{{.SupportBlockName}}.id
418419 description = "a test instance"
@@ -1227,3 +1228,83 @@ func testAccInstanceDestroy(s *terraform.State) error {
12271228
12281229 return nil
12291230}
1231+
1232+ func TestFilterBootDiskFromDisks (t * testing.T ) {
1233+ boot_disk := oxide.InstanceDiskAttachment {
1234+ Name : "testboot01" ,
1235+ Type : oxide .InstanceDiskAttachmentTypeAttach ,
1236+ }
1237+
1238+ tests := []struct {
1239+ boot_disk oxide.InstanceDiskAttachment
1240+ disks []oxide.InstanceDiskAttachment
1241+ want []oxide.InstanceDiskAttachment
1242+ }{
1243+ {
1244+ boot_disk : boot_disk ,
1245+ disks : []oxide.InstanceDiskAttachment {
1246+ boot_disk ,
1247+ {
1248+ Name : "testdisk01" ,
1249+ Type : oxide .InstanceDiskAttachmentTypeAttach ,
1250+ },
1251+ {
1252+ Name : "testdisk01" ,
1253+ Type : oxide .InstanceDiskAttachmentTypeAttach ,
1254+ },
1255+ },
1256+ want : []oxide.InstanceDiskAttachment {
1257+ {
1258+ Name : "testdisk01" ,
1259+ Type : oxide .InstanceDiskAttachmentTypeAttach ,
1260+ },
1261+ {
1262+ Name : "testdisk01" ,
1263+ Type : oxide .InstanceDiskAttachmentTypeAttach ,
1264+ },
1265+ },
1266+ },
1267+ {
1268+ boot_disk : oxide.InstanceDiskAttachment {},
1269+ disks : []oxide.InstanceDiskAttachment {
1270+ {
1271+ Name : "testdisk01" ,
1272+ Type : oxide .InstanceDiskAttachmentTypeAttach ,
1273+ },
1274+ {
1275+ Name : "testdisk01" ,
1276+ Type : oxide .InstanceDiskAttachmentTypeAttach ,
1277+ },
1278+ {
1279+ Name : "testboot01" ,
1280+ Type : oxide .InstanceDiskAttachmentTypeAttach ,
1281+ },
1282+ },
1283+ want : []oxide.InstanceDiskAttachment {
1284+ {
1285+ Name : "testdisk01" ,
1286+ Type : oxide .InstanceDiskAttachmentTypeAttach ,
1287+ },
1288+ {
1289+ Name : "testdisk01" ,
1290+ Type : oxide .InstanceDiskAttachmentTypeAttach ,
1291+ },
1292+ {
1293+ Name : "testboot01" ,
1294+ Type : oxide .InstanceDiskAttachmentTypeAttach ,
1295+ },
1296+ },
1297+ },
1298+ {
1299+ boot_disk : oxide.InstanceDiskAttachment {},
1300+ disks : []oxide.InstanceDiskAttachment {},
1301+ want : []oxide.InstanceDiskAttachment {},
1302+ },
1303+ }
1304+ for _ , tt := range tests {
1305+ disks := filterBootDiskFromDisks (tt .disks , & tt .boot_disk )
1306+ if ! reflect .DeepEqual (disks , tt .want ) {
1307+ t .Errorf ("want: %+v, got: %+v" , tt .want , disks )
1308+ }
1309+ }
1310+ }
0 commit comments