Skip to content

Commit 9eb4e1a

Browse files
committed
test: Implement incus image alias nested block
Signed-off-by: Ruihua Wen <[email protected]>
1 parent c954f1e commit 9eb4e1a

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

internal/image/resource_image_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,35 @@ func TestAccImage_sourceFileUnifiedImage(t *testing.T) {
418418
})
419419
}
420420

421+
func TestAccImage_alias_blocks(t *testing.T) {
422+
alias1 := petname.Generate(2, "-")
423+
alias2 := petname.Generate(2, "-")
424+
425+
resource.Test(t, resource.TestCase{
426+
PreCheck: func() { acctest.PreCheck(t) },
427+
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
428+
Steps: []resource.TestStep{
429+
{
430+
Config: testAccImage_aliasBlocks(alias1, alias2),
431+
Check: resource.ComposeTestCheckFunc(
432+
resource.TestCheckResourceAttr("incus_image.img1", "source_image.remote", "images"),
433+
resource.TestCheckResourceAttr("incus_image.img1", "source_image.name", "alpine/edge"),
434+
resource.TestCheckResourceAttr("incus_image.img1", "alias.#", "2"),
435+
resource.TestCheckTypeSetElemNestedAttrs("incus_image.img1", "alias.*", map[string]string{
436+
"name": alias1,
437+
"description": "Test alias 1",
438+
}),
439+
resource.TestCheckTypeSetElemNestedAttrs("incus_image.img1", "alias.*", map[string]string{
440+
"name": alias2,
441+
"description": "Test alias 2",
442+
}),
443+
resource.TestCheckResourceAttr("incus_image.img1", "copied_aliases.#", "0"),
444+
),
445+
},
446+
},
447+
})
448+
}
449+
421450
func testAccImage_basic() string {
422451
return `
423452
resource "incus_image" "img1" {
@@ -746,3 +775,24 @@ resource "incus_image" "from_file" {
746775
747776
`, targetData, strings.Join(aliases, `","`))
748777
}
778+
779+
func testAccImage_aliasBlocks(alias1, alias2 string) string {
780+
return fmt.Sprintf(`
781+
resource "incus_image" "img1" {
782+
source_image = {
783+
remote = "images"
784+
name = "alpine/edge"
785+
}
786+
787+
alias {
788+
name = "%s"
789+
description = "Test alias 1"
790+
}
791+
792+
alias {
793+
name = "%s"
794+
description = "Test alias 2"
795+
}
796+
}
797+
`, alias1, alias2)
798+
}

0 commit comments

Comments
 (0)