Skip to content

Commit

Permalink
Attempt to add data source test
Browse files Browse the repository at this point in the history
  • Loading branch information
briancain committed Feb 19, 2025
1 parent 4dc2645 commit 0581370
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
45 changes: 45 additions & 0 deletions internal/provider/waypoint/data_source_waypoint_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,44 @@ func TestAcc_Waypoint_Data_template_with_variable_options(t *testing.T) {
})
}

func TestAcc_Waypoint_Data_template_with_actions(t *testing.T) {
t.Parallel()

var (
appTemplateModel waypoint.TemplateResourceModel
actionCfgModel waypoint.ActionResourceModel
)
resourceName := "hcp_waypoint_template.actions_template_test"
actionResourceName := "hcp_waypoint_action.test"
dataSourceName := "data." + resourceName
name := generateRandomName()

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
CheckDestroy: testAccCheckWaypointTemplateDestroy(t, &appTemplateModel),
Steps: []resource.TestStep{
{
// establish the base template
Config: testTemplateWithActionsConfig(name, actionResourceName),
Check: resource.ComposeTestCheckFunc(
testAccCheckWaypointTemplateExists(t, resourceName, &appTemplateModel),
testAccCheckWaypointActionExists(t, actionResourceName, &actionCfgModel),
),
},
{
// add a data source config to read the template
Config: testDataAppTemplateWithAction(name, actionResourceName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "name", name),
resource.TestCheckResourceAttr(dataSourceName, "actions.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "actions.0.name", actionResourceName),
),
},
},
})
}

func testDataAppTemplateConfig(name string) string {
return fmt.Sprintf(`%s
data "hcp_waypoint_template" "test" {
Expand All @@ -111,3 +149,10 @@ data "hcp_waypoint_template" "var_opts_test" {
name = hcp_waypoint_template.var_opts_test.name
}`, testTemplateConfigWithVarOpts(name))
}

func testDataAppTemplateWithAction(templateName, actionName string) string {
return fmt.Sprintf(`%s
data "hcp_waypoint_template" "actions_template_test" {
name = hcp_waypoint_template.actions_template_test.name
}`, testTemplateWithActionsConfig(templateName, actionName))
}
2 changes: 0 additions & 2 deletions internal/provider/waypoint/resource_waypoint_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ func TestAcc_Waypoint_Create_Template_with_actions(t *testing.T) {
name := generateRandomName()
actionName := generateRandomName()

templateResourceStr := testTemplateWithActionsConfig(name, actionName)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Expand Down

0 comments on commit 0581370

Please sign in to comment.