Skip to content

Commit

Permalink
internal/network: Add test for nullable config
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
(cherry picked from commit 97258f8d4bc2bd5d58345f148f422f27c1687b5e)
Signed-off-by: Din Music <[email protected]>
  • Loading branch information
stgraber authored and MusicDin committed Jul 8, 2024
1 parent a0a643e commit be88006
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions internal/network/resource_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ func TestAccNetwork_description(t *testing.T) {
})
}

func TestAccNetwork_nullable(t *testing.T) {
networkName := acctest.GenerateName(2, "-")

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccNetwork_nullable(networkName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("lxd_network.network", "name", networkName),
resource.TestCheckResourceAttr("lxd_network.network", "type", "bridge"),
resource.TestCheckResourceAttr("lxd_network.network", "config.%", "2"),
resource.TestCheckNoResourceAttr("lxd_network.network", "config.ipv4.address"),
resource.TestCheckResourceAttr("lxd_network.network", "config.ipv6.address", "none"),
),
},
},
})
}

func TestAccNetwork_attach(t *testing.T) {
networkName := acctest.GenerateName(2, "-")
profileName := acctest.GenerateName(2, "-")
Expand Down Expand Up @@ -276,6 +297,23 @@ resource "lxd_network" "network" {
`, networkName)
}

func testAccNetwork_nullable(networkName string) string {
return fmt.Sprintf(`
locals {
foo = "bar"
}
resource "lxd_network" "network" {
name = "%s"
config = {
"ipv4.address" = local.foo == "bar" ? null : "10.0.0.1/24"
"ipv6.address" = "none"
}
}
`, networkName)
}

func testAccNetwork_attach(networkName string, profileName string, instanceName string) string {
return fmt.Sprintf(`
resource "lxd_network" "network" {
Expand Down

0 comments on commit be88006

Please sign in to comment.