Skip to content

Commit

Permalink
feat: [PIPE-22953]: Add Import template from Non default branch test (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ar7-harness authored Nov 13, 2024
1 parent 62aa516 commit cd9ad28
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions internal/service/pipeline/template/resource_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,38 @@ func TestAccResourceTemplate_ProjectScopeImportFromGit(t *testing.T) {
})
}

func TestAccResourceTemplate_ProjectScopeImportFromGitNonDefaultBranch(t *testing.T) {
id := "projecttemplate"
name := id
resourceName := "harness_platform_template.test"

resource.UnitTest(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
"time": {},
"null": {},
},
CheckDestroy: testAccTemplateDestroy(resourceName),
Steps: []resource.TestStep{
{
Config: testAccResourceTemplateProjectScopeImportFromGitNonDefaultBranch(id, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", "projecttemplate"),
resource.TestCheckResourceAttr(resourceName, "name", "projecttemplate"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: acctest.ProjectResourceImportStateIdFunc(resourceName),
ImportStateVerifyIgnore: []string{"git_details.0.commit_message", "git_details.0.connector_ref", "git_details.0.store_type", "comments", "git_details.0.branch_name", "git_details.0.file_path", "git_details.0.last_commit_id", "git_details.0.repo_name", "git_import_details.#", "git_import_details.0.%", "git_import_details.0.branch_name", "git_import_details.0.connector_ref", "git_import_details.0.file_path", "git_import_details.0.is_force_import", "git_import_details.0.repo_name", "import_from_git", "is_stable", "template_import_request.#", "template_import_request.0.%", "template_import_request.0.template_description", "template_import_request.0.template_name", "template_import_request.0.template_version", "template_yaml", "version", "git_details.0.last_object_id"},
},
},
})
}

func TestAccResourceTemplate_AccountScopeImportFromGit(t *testing.T) {
id := "accounttemplate"
name := id
Expand Down Expand Up @@ -1443,6 +1475,40 @@ func testAccResourceTemplateProjectScopeImportFromGit(id string, name string) st
`, id, name)
}

func testAccResourceTemplateProjectScopeImportFromGitNonDefaultBranch(id string, name string) string {
// This has project and org id static due to its config in the git.
return fmt.Sprintf(`
resource "harness_platform_template" "test" {
identifier = "%[1]s"
org_id = "default"
project_id = "TF_Pipeline_Test"
name = "%[2]s"
version = "v2"
import_from_git = true
git_import_details {
branch_name = "main-patch"
file_path = ".harness/projecttemplate.yaml"
connector_ref = "account.TF_open_repo_github_connector"
repo_name = "open-repo"
}
template_import_request {
template_name = "%[2]s"
template_version = "v2"
template_description = ""
}
}
resource "time_sleep" "wait_4_seconds" {
depends_on = [harness_platform_template.test]
destroy_duration = "4s"
}
resource "null_resource" "next" {
depends_on = [time_sleep.wait_4_seconds]
}
`, id, name)
}

func testAccResourceTemplateAccountScopeImportFromGit(id string, name string) string {
return fmt.Sprintf(`
resource "harness_platform_template" "test" {
Expand Down

0 comments on commit cd9ad28

Please sign in to comment.