Skip to content

Commit

Permalink
Add test that changes inventory type
Browse files Browse the repository at this point in the history
  • Loading branch information
Omicron7 committed Nov 13, 2024
1 parent 05ca877 commit 97aa4d5
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions internal/provider/project_inventory_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,60 @@ func TestAcc_ProjectInventoryResource_basicTerraformWorkspace(t *testing.T) {
},
})
}

func TestAcc_ProjectInventoryResource_updateType(t *testing.T) {
nameSuffix := acctest.RandString(8)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccProjectInventoryFileConfig(nameSuffix, "path/to/inventory"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccProjectInventoryExists("semaphoreui_project_inventory.test", InventoryFile),
resource.TestCheckResourceAttr("semaphoreui_project_inventory.test", "name", fmt.Sprintf("Test %s", nameSuffix)),

resource.TestCheckResourceAttr("semaphoreui_project_inventory.test", "file.%", "3"),
resource.TestCheckResourceAttr("semaphoreui_project_inventory.test", "file.path", "path/to/inventory"),
resource.TestCheckNoResourceAttr("semaphoreui_project_inventory.test", "file.become_key_id"),
resource.TestCheckNoResourceAttr("semaphoreui_project_inventory.test", "file.repository_id"),

resource.TestCheckNoResourceAttr("semaphoreui_project_inventory.test", "static"),
resource.TestCheckNoResourceAttr("semaphoreui_project_inventory.test", "static_yaml"),
resource.TestCheckNoResourceAttr("semaphoreui_project_inventory.test", "terraform_workspace"),

resource.TestCheckResourceAttrSet("semaphoreui_project_inventory.test", "id"),
resource.TestCheckResourceAttrSet("semaphoreui_project_inventory.test", "project_id"),
resource.TestCheckResourceAttrSet("semaphoreui_project_inventory.test", "ssh_key_id"),
),
},
// Update and Read testing
{
Config: testAccProjectInventoryTerraformWorkspaceConfig(nameSuffix, "testing"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccProjectInventoryExists("semaphoreui_project_inventory.test", InventoryTerraformWorkspace),
resource.TestCheckResourceAttr("semaphoreui_project_inventory.test", "name", fmt.Sprintf("Test %s", nameSuffix)),

resource.TestCheckResourceAttr("semaphoreui_project_inventory.test", "terraform_workspace.%", "1"),
resource.TestCheckResourceAttr("semaphoreui_project_inventory.test", "terraform_workspace.workspace", "testing"),

resource.TestCheckNoResourceAttr("semaphoreui_project_inventory.test", "static"),
resource.TestCheckNoResourceAttr("semaphoreui_project_inventory.test", "static_yaml"),
resource.TestCheckNoResourceAttr("semaphoreui_project_inventory.test", "file"),

resource.TestCheckResourceAttrSet("semaphoreui_project_inventory.test", "id"),
resource.TestCheckResourceAttrSet("semaphoreui_project_inventory.test", "project_id"),
resource.TestCheckResourceAttrSet("semaphoreui_project_inventory.test", "ssh_key_id"),
),
},
// Delete testing
{
Config: testAccProjectInventoryEmptyConfig(nameSuffix, ""),
Check: resource.ComposeAggregateTestCheckFunc(
testAccResourceNotExists("semaphoreui_project_inventory.test"),
),
},
},
})
}

0 comments on commit 97aa4d5

Please sign in to comment.