From a82a7106a267c7243ea28de5a826554154c31f44 Mon Sep 17 00:00:00 2001 From: Piotr Truszkowski Date: Wed, 28 Feb 2024 16:09:31 +0100 Subject: [PATCH 1/2] extend VCS tests --- spacelift/resource_module_test.go | 20 - spacelift/resource_stack_test.go | 21 - spacelift/vcs_integration_test.go | 997 ++++++++++++++++++++++++++++++ 3 files changed, 997 insertions(+), 41 deletions(-) create mode 100644 spacelift/vcs_integration_test.go diff --git a/spacelift/resource_module_test.go b/spacelift/resource_module_test.go index a99b8b6a..dc2cefc8 100644 --- a/spacelift/resource_module_test.go +++ b/spacelift/resource_module_test.go @@ -69,26 +69,6 @@ func TestModuleResource(t *testing.T) { }) }) - t.Run("vcs integration id", func(t *testing.T) { - testSteps(t, []resource.TestStep{ - { - Config: `resource "spacelift_module" "test" { - name = "integration-id-check-test" - repository = "multimodule" - branch = "main" - administrative = false - gitlab { - namespace = "spacelift-ci" - } - }`, - Check: Resource( - "spacelift_module.test", - Attribute("gitlab.0.id", Equals(testConfig.SourceCode.Gitlab.Default.ID)), - ), - }, - }) - }) - t.Run("project root and custom name", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) diff --git a/spacelift/resource_stack_test.go b/spacelift/resource_stack_test.go index f9981f2d..af30da40 100644 --- a/spacelift/resource_stack_test.go +++ b/spacelift/resource_stack_test.go @@ -356,27 +356,6 @@ func TestStackResource(t *testing.T) { }}) }) - t.Run("vcs integration id", func(t *testing.T) { - testSteps(t, []resource.TestStep{ - { - Config: `resource "spacelift_stack" "test" { - name = "VCS Integration ID setting test" - repository = "multimodule" - branch = "main" - administrative = false - manage_state = true - gitlab { - namespace = "spacelift-ci" - } - }`, - Check: Resource( - "spacelift_stack.test", - Attribute("gitlab.0.id", Equals(testConfig.SourceCode.Gitlab.Default.ID)), - ), - }, - }) - }) - t.Run("external state access", func(t *testing.T) { testSteps(t, []resource.TestStep{ { diff --git a/spacelift/vcs_integration_test.go b/spacelift/vcs_integration_test.go new file mode 100644 index 00000000..1c50e87e --- /dev/null +++ b/spacelift/vcs_integration_test.go @@ -0,0 +1,997 @@ +package spacelift + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + . "github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal/testhelpers" +) + +func TestVCSIntegration(t *testing.T) { + randomID := func() string { return acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) } + + for _, resourceName := range []string{"spacelift_stack", "spacelift_module"} { + t.Run(resourceName, func(t *testing.T) { + t.Run("setting up ID", func(t *testing.T) { + randomID := func() string { return acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) } + + testCases := []struct { + name string + repository string + branch string + space string + provider string + dataSource string + attributeValue string + attribute string + }{ + // Azure Dev Ops + { + name: "azure-devops-with-non-specified-integration-" + randomID(), + repository: "spacelift-ci", + branch: "main", + space: "root", + provider: `azure_devops { + project = "spacelift-ci" + }`, + attribute: "azure_devops.0.id", + attributeValue: testConfig.SourceCode.AzureDevOps.Default.ID, + }, + { + name: "azure-devops-with-an-empty-integration-id-" + randomID(), + repository: "spacelift-ci", + branch: "main", + space: "root", + provider: `azure_devops { + project = "spacelift-ci" + id = "" + }`, + attribute: "azure_devops.0.id", + attributeValue: testConfig.SourceCode.AzureDevOps.Default.ID, + }, + { + name: "azure-devops-with-default-integration-" + randomID(), + repository: "spacelift-ci", + branch: "main", + space: "root", + provider: `azure_devops { + project = "spacelift-ci" + id = "` + testConfig.SourceCode.AzureDevOps.Default.ID + `" + }`, + attribute: "azure_devops.0.id", + attributeValue: testConfig.SourceCode.AzureDevOps.Default.ID, + }, + { + name: "azure-devops-with-space-level-integration-" + randomID(), + repository: "spacelift-ci", + branch: "main", + space: testConfig.SourceCode.AzureDevOps.SpaceLevel.Space, + provider: `azure_devops { + project = "spacelift-ci" + id = "` + testConfig.SourceCode.AzureDevOps.SpaceLevel.ID + `" + }`, + attribute: "azure_devops.0.id", + attributeValue: testConfig.SourceCode.AzureDevOps.SpaceLevel.ID, + }, + { + name: "azure-devops-with-default-integration-from-data-source-" + randomID(), + repository: "spacelift-ci", + branch: "main", + space: "root", + provider: `azure_devops { + project = "spacelift-ci" + id = data.spacelift_azure_devops_integration.test.id + }`, + dataSource: `data "spacelift_azure_devops_integration" "test" {}`, + attribute: "azure_devops.0.id", + attributeValue: testConfig.SourceCode.AzureDevOps.Default.ID, + }, + { + name: "azure-devops-with-space-level-integration-from-data-source-" + randomID(), + repository: "spacelift-ci", + branch: "main", + space: testConfig.SourceCode.AzureDevOps.SpaceLevel.Space, + provider: `azure_devops { + project = "spacelift-ci" + id = data.spacelift_azure_devops_integration.test.id + }`, + dataSource: `data "spacelift_azure_devops_integration" "test" { + id = "` + testConfig.SourceCode.AzureDevOps.SpaceLevel.ID + `" + }`, + attribute: "azure_devops.0.id", + attributeValue: testConfig.SourceCode.AzureDevOps.SpaceLevel.ID, + }, + // Bitbucket Cloud + { + name: "bitbucket-cloud-with-non-specified-integration-" + randomID(), + repository: "empty", + branch: "master", + space: "root", + provider: `bitbucket_cloud { + namespace = "thespacelift" + }`, + attribute: "bitbucket_cloud.0.id", + attributeValue: testConfig.SourceCode.BitbucketCloud.Default.ID, + }, + { + name: "bitbucket-cloud-with-an-empty-integration-id-" + randomID(), + repository: "empty", + branch: "master", + space: "root", + provider: `bitbucket_cloud { + namespace = "thespacelift" + id = "" + }`, + attribute: "bitbucket_cloud.0.id", + attributeValue: testConfig.SourceCode.BitbucketCloud.Default.ID, + }, + { + name: "bitbucket-cloud-with-default-integration-" + randomID(), + repository: "empty", + branch: "master", + space: "root", + provider: `bitbucket_cloud { + namespace = "thespacelift" + id = "` + testConfig.SourceCode.BitbucketCloud.Default.ID + `" + }`, + attribute: "bitbucket_cloud.0.id", + attributeValue: testConfig.SourceCode.BitbucketCloud.Default.ID, + }, + { + name: "bitbucket-cloud-with-space-level-integration-" + randomID(), + repository: "empty", + branch: "master", + space: testConfig.SourceCode.BitbucketCloud.SpaceLevel.Space, + provider: `bitbucket_cloud { + namespace = "thespacelift" + id = "` + testConfig.SourceCode.BitbucketCloud.SpaceLevel.ID + `" + }`, + attribute: "bitbucket_cloud.0.id", + attributeValue: testConfig.SourceCode.BitbucketCloud.SpaceLevel.ID, + }, + { + name: "bitbucket-cloud-with-default-integration-from-data-source-" + randomID(), + repository: "empty", + branch: "master", + space: "root", + provider: `bitbucket_cloud { + namespace = "thespacelift" + id = data.spacelift_bitbucket_cloud_integration.test.id + }`, + dataSource: `data "spacelift_bitbucket_cloud_integration" "test" {}`, + attribute: "bitbucket_cloud.0.id", + attributeValue: testConfig.SourceCode.BitbucketCloud.Default.ID, + }, + { + name: "bitbucket-cloud-with-space-level-integration-from-data-source-" + randomID(), + repository: "empty", + branch: "master", + space: testConfig.SourceCode.BitbucketCloud.SpaceLevel.Space, + provider: `bitbucket_cloud { + namespace = "thespacelift" + id = data.spacelift_bitbucket_cloud_integration.test.id + }`, + dataSource: `data "spacelift_bitbucket_cloud_integration" "test" { + id = "` + testConfig.SourceCode.BitbucketCloud.SpaceLevel.ID + `" + }`, + attribute: "bitbucket_cloud.0.id", + attributeValue: testConfig.SourceCode.BitbucketCloud.SpaceLevel.ID, + }, + // Bitbucket Datacenter + { + name: "bitbucket-datacenter-with-non-specified-integration-" + randomID(), + repository: "tfprovider-test", + branch: "master", + space: "root", + provider: `bitbucket_datacenter { + namespace = "E2E" + }`, + attribute: "bitbucket_datacenter.0.id", + attributeValue: testConfig.SourceCode.BitbucketDatacenter.Default.ID, + }, + { + name: "bitbucket-datacenter-with-an-empty-integration-id-" + randomID(), + repository: "tfprovider-test", + branch: "master", + space: "root", + provider: `bitbucket_datacenter { + namespace = "E2E" + id = "" + }`, + attribute: "bitbucket_datacenter.0.id", + attributeValue: testConfig.SourceCode.BitbucketDatacenter.Default.ID, + }, + { + name: "bitbucket-datacenter-with-default-integration-" + randomID(), + repository: "tfprovider-test", + branch: "master", + space: "root", + provider: `bitbucket_datacenter { + namespace = "E2E" + id = "` + testConfig.SourceCode.BitbucketDatacenter.Default.ID + `" + }`, + attribute: "bitbucket_datacenter.0.id", + attributeValue: testConfig.SourceCode.BitbucketDatacenter.Default.ID, + }, + { + name: "bitbucket-datacenter-with-space-level-integration-" + randomID(), + repository: "tfprovider-test", + branch: "master", + space: testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.Space, + provider: `bitbucket_datacenter { + namespace = "E2E" + id = "` + testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.ID + `" + }`, + attribute: "bitbucket_datacenter.0.id", + attributeValue: testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.ID, + }, + { + name: "bitbucket-datacenter-with-default-integration-from-data-source-" + randomID(), + repository: "tfprovider-test", + branch: "master", + space: "root", + provider: `bitbucket_datacenter { + namespace = "E2E" + id = data.spacelift_bitbucket_datacenter_integration.test.id + }`, + dataSource: `data "spacelift_bitbucket_datacenter_integration" "test" {}`, + attribute: "bitbucket_datacenter.0.id", + attributeValue: testConfig.SourceCode.BitbucketDatacenter.Default.ID, + }, + { + name: "bitbucket-datacenter-with-space-level-integration-from-data-source-" + randomID(), + repository: "tfprovider-test", + branch: "master", + space: testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.Space, + provider: `bitbucket_datacenter { + namespace = "E2E" + id = data.spacelift_bitbucket_datacenter_integration.test.id + }`, + dataSource: `data "spacelift_bitbucket_datacenter_integration" "test" { + id = "` + testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.ID + `" + }`, + attribute: "bitbucket_datacenter.0.id", + attributeValue: testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.ID, + }, + // GitHub Enterprise + { + name: "github-with-non-specified-integration-" + randomID(), + repository: "empty", + branch: "main", + space: "root", + provider: `github_enterprise { + namespace = "spacelift-ci-org" + }`, + attribute: "github_enterprise.0.id", + attributeValue: testConfig.SourceCode.GithubEnterprise.Default.ID, + }, + { + name: "github-with-an-empty-integration-id-" + randomID(), + repository: "empty", + branch: "main", + space: "root", + provider: `github_enterprise { + namespace = "spacelift-ci-org" + id = "" + }`, + attribute: "github_enterprise.0.id", + attributeValue: testConfig.SourceCode.GithubEnterprise.Default.ID, + }, + { + name: "github-with-default-integration-" + randomID(), + repository: "empty", + branch: "main", + space: "root", + provider: `github_enterprise { + namespace = "spacelift-ci-org" + id = "` + testConfig.SourceCode.GithubEnterprise.Default.ID + `" + }`, + attribute: "github_enterprise.0.id", + attributeValue: testConfig.SourceCode.GithubEnterprise.Default.ID, + }, + { + name: "github-with-space-level-integration-" + randomID(), + repository: "empty", + branch: "main", + space: testConfig.SourceCode.GithubEnterprise.SpaceLevel.Space, + provider: `github_enterprise { + namespace = "spacelift-ci-org" + id = "` + testConfig.SourceCode.GithubEnterprise.SpaceLevel.ID + `" + }`, + attribute: "github_enterprise.0.id", + attributeValue: testConfig.SourceCode.GithubEnterprise.SpaceLevel.ID, + }, + { + name: "github-with-default-integration-from-data-source-" + randomID(), + repository: "empty", + branch: "main", + space: "root", + provider: `github_enterprise { + namespace = "spacelift-ci-org" + id = data.spacelift_github_enterprise_integration.test.id + }`, + dataSource: `data "spacelift_github_enterprise_integration" "test" {}`, + attribute: "github_enterprise.0.id", + attributeValue: testConfig.SourceCode.GithubEnterprise.Default.ID, + }, + { + name: "github-with-space-level-integration-from-data-source-" + randomID(), + repository: "empty", + branch: "main", + space: testConfig.SourceCode.GithubEnterprise.SpaceLevel.Space, + provider: `github_enterprise { + namespace = "spacelift-ci-org" + id = data.spacelift_github_enterprise_integration.test.id + }`, + dataSource: `data "spacelift_github_enterprise_integration" "test" { + id = "` + testConfig.SourceCode.GithubEnterprise.SpaceLevel.ID + `" + }`, + attribute: "github_enterprise.0.id", + attributeValue: testConfig.SourceCode.GithubEnterprise.SpaceLevel.ID, + }, + // GitLab + { + name: "gitlab-with-non-specified-integration-" + randomID(), + repository: "multimodule", + branch: "main", + space: "root", + provider: `gitlab { + namespace = "spacelift-ci" + }`, + attribute: "gitlab.0.id", + attributeValue: testConfig.SourceCode.Gitlab.Default.ID, + }, + { + name: "gitlab-with-an-empty-integration-id-" + randomID(), + repository: "multimodule", + branch: "main", + space: "root", + provider: `gitlab { + namespace = "spacelift-ci" + id = "" + }`, + attribute: "gitlab.0.id", + attributeValue: testConfig.SourceCode.Gitlab.Default.ID, + }, + { + name: "gitlab-with-default-integration-" + randomID(), + repository: "multimodule", + branch: "main", + space: "root", + provider: `gitlab { + namespace = "spacelift-ci" + id = "` + testConfig.SourceCode.Gitlab.Default.ID + `" + }`, + attribute: "gitlab.0.id", + attributeValue: testConfig.SourceCode.Gitlab.Default.ID, + }, + { + name: "gitlab-with-space-level-integration-" + randomID(), + repository: "multimodule", + branch: "main", + space: testConfig.SourceCode.Gitlab.SpaceLevel.Space, + provider: `gitlab { + namespace = "spacelift-ci" + id = "` + testConfig.SourceCode.Gitlab.SpaceLevel.ID + `" + }`, + attribute: "gitlab.0.id", + attributeValue: testConfig.SourceCode.Gitlab.SpaceLevel.ID, + }, + { + name: "gitlab-with-default-integration-from-data-source-" + randomID(), + repository: "multimodule", + branch: "main", + space: "root", + provider: `gitlab { + namespace = "spacelift-ci" + id = data.spacelift_gitlab_integration.test.id + }`, + dataSource: `data "spacelift_gitlab_integration" "test" {}`, + attribute: "gitlab.0.id", + attributeValue: testConfig.SourceCode.Gitlab.Default.ID, + }, + { + name: "gitlab-with-space-level-integration-from-data-source-" + randomID(), + repository: "multimodule", + branch: "main", + space: testConfig.SourceCode.Gitlab.SpaceLevel.Space, + provider: `gitlab { + namespace = "spacelift-ci" + id = data.spacelift_gitlab_integration.test.id + }`, + dataSource: `data "spacelift_gitlab_integration" "test" { + id = "` + testConfig.SourceCode.Gitlab.SpaceLevel.ID + `" + }`, + attribute: "gitlab.0.id", + attributeValue: testConfig.SourceCode.Gitlab.SpaceLevel.ID, + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + config := fmt.Sprintf(` + %s + + resource "`+resourceName+`" "test" { + name = "%s" + repository = "%s" + branch = "%s" + space_id = "%s" + administrative = false + %s + }`, tc.dataSource, tc.name, tc.repository, tc.branch, tc.space, tc.provider) + + var tfstateSerial int64 + testSteps(t, []resource.TestStep{ + { + Config: config, + Check: func(tfstate *terraform.State) error { + tfstateSerial = tfstate.Serial + return Resource(resourceName+".test", Attribute(tc.attribute, Equals(tc.attributeValue)))(tfstate) + }, + }, + { + Config: config, + Check: func(tfstate *terraform.State) error { + // We need to check the serials to make sure nothing changed + if serial := tfstate.Serial; serial != tfstateSerial { + return fmt.Errorf("serials do not match: %d != %d", serial, tfstateSerial) + } + return nil + }, + }, + }) + }) + } + }) + + t.Run("change ID", func(t *testing.T) { + type testCaseStepAttribute struct { + key string + value string + } + + type testCaseStep struct { + dataSource string + provider string + attribute testCaseStepAttribute + } + + testCases := []struct { + name string + repository string + branch string + space string + steps []testCaseStep + }{ + // Azure Dev Ops + { + name: "azure-devops-with-changing-vcs-id-" + randomID(), + repository: "spacelift-ci", + branch: "main", + space: testConfig.SourceCode.AzureDevOps.SpaceLevel.Space, + steps: []testCaseStep{ + { + dataSource: "", + provider: `azure_devops { + project = "spacelift-ci" + }`, + attribute: testCaseStepAttribute{ + key: "azure_devops.0.id", + value: testConfig.SourceCode.AzureDevOps.Default.ID, + }, + }, + { + dataSource: "", + provider: `azure_devops { + project = "spacelift-ci" + id = "` + testConfig.SourceCode.AzureDevOps.SpaceLevel.ID + `" + }`, + attribute: testCaseStepAttribute{ + key: "azure_devops.0.id", + value: testConfig.SourceCode.AzureDevOps.SpaceLevel.ID, + }, + }, + { + dataSource: `data "spacelift_azure_devops_integration" "test" { + id = "` + testConfig.SourceCode.AzureDevOps.SpaceLevel.ID + `" + }`, + provider: `azure_devops { + project = "spacelift-ci" + id = data.spacelift_azure_devops_integration.test.id + }`, + attribute: testCaseStepAttribute{ + key: "azure_devops.0.id", + value: testConfig.SourceCode.AzureDevOps.SpaceLevel.ID, + }, + }, + { + dataSource: `data "spacelift_azure_devops_integration" "test" {}`, + provider: `azure_devops { + project = "spacelift-ci" + id = data.spacelift_azure_devops_integration.test.id + }`, + attribute: testCaseStepAttribute{ + key: "azure_devops.0.id", + value: testConfig.SourceCode.AzureDevOps.Default.ID, + }, + }, + { + dataSource: "", + provider: `azure_devops { + project = "spacelift-ci" + }`, + attribute: testCaseStepAttribute{ + key: "azure_devops.0.id", + value: testConfig.SourceCode.AzureDevOps.Default.ID, + }, + }, + }, + }, + // Bitbucket Cloud + { + name: "bitbucket-cloud-with-changing-vcs-id-" + randomID(), + repository: "empty", + branch: "master", + space: testConfig.SourceCode.BitbucketCloud.SpaceLevel.Space, + steps: []testCaseStep{ + { + dataSource: "", + provider: `bitbucket_cloud { + namespace = "thespacelift" + }`, + attribute: testCaseStepAttribute{ + key: "bitbucket_cloud.0.id", + value: testConfig.SourceCode.BitbucketCloud.Default.ID, + }, + }, + { + dataSource: "", + provider: `bitbucket_cloud { + namespace = "thespacelift" + id = "` + testConfig.SourceCode.BitbucketCloud.SpaceLevel.ID + `" + }`, + attribute: testCaseStepAttribute{ + key: "bitbucket_cloud.0.id", + value: testConfig.SourceCode.BitbucketCloud.SpaceLevel.ID, + }, + }, + { + dataSource: `data "spacelift_bitbucket_cloud_integration" "test" { + id = "` + testConfig.SourceCode.BitbucketCloud.SpaceLevel.ID + `" + }`, + provider: `bitbucket_cloud { + namespace = "thespacelift" + id = data.spacelift_bitbucket_cloud_integration.test.id + }`, + attribute: testCaseStepAttribute{ + key: "bitbucket_cloud.0.id", + value: testConfig.SourceCode.BitbucketCloud.SpaceLevel.ID, + }, + }, + { + dataSource: `data "spacelift_bitbucket_cloud_integration" "test" {}`, + provider: `bitbucket_cloud { + namespace = "thespacelift" + id = data.spacelift_bitbucket_cloud_integration.test.id + }`, + attribute: testCaseStepAttribute{ + key: "bitbucket_cloud.0.id", + value: testConfig.SourceCode.BitbucketCloud.Default.ID, + }, + }, + { + dataSource: "", + provider: `bitbucket_cloud { + namespace = "thespacelift" + }`, + attribute: testCaseStepAttribute{ + key: "bitbucket_cloud.0.id", + value: testConfig.SourceCode.BitbucketCloud.Default.ID, + }, + }, + }, + }, + // Bitbucket Datacenter + { + name: "bitbucket-datacenter-with-changing-vcs-id-" + randomID(), + repository: "tfprovider-test", + branch: "master", + space: testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.Space, + steps: []testCaseStep{ + { + dataSource: "", + provider: `bitbucket_datacenter { + namespace = "E2E" + }`, + attribute: testCaseStepAttribute{ + key: "bitbucket_datacenter.0.id", + value: testConfig.SourceCode.BitbucketDatacenter.Default.ID, + }, + }, + { + dataSource: "", + provider: `bitbucket_datacenter { + namespace = "E2E" + id = "` + testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.ID + `" + }`, + attribute: testCaseStepAttribute{ + key: "bitbucket_datacenter.0.id", + value: testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.ID, + }, + }, + { + dataSource: `data "spacelift_bitbucket_datacenter_integration" "test" { + id = "` + testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.ID + `" + }`, + provider: `bitbucket_datacenter { + namespace = "E2E" + id = data.spacelift_bitbucket_datacenter_integration.test.id + }`, + attribute: testCaseStepAttribute{ + key: "bitbucket_datacenter.0.id", + value: testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.ID, + }, + }, + { + dataSource: `data "spacelift_bitbucket_datacenter_integration" "test" {}`, + provider: `bitbucket_datacenter { + namespace = "E2E" + id = data.spacelift_bitbucket_datacenter_integration.test.id + }`, + attribute: testCaseStepAttribute{ + key: "bitbucket_datacenter.0.id", + value: testConfig.SourceCode.BitbucketDatacenter.Default.ID, + }, + }, + { + dataSource: "", + provider: `bitbucket_datacenter { + namespace = "E2E" + }`, + attribute: testCaseStepAttribute{ + key: "bitbucket_datacenter.0.id", + value: testConfig.SourceCode.BitbucketDatacenter.Default.ID, + }, + }, + }, + }, + // GitHub Enterprise + { + name: "github-enterprise-with-changing-vcs-id-" + randomID(), + repository: "empty", + branch: "main", + space: testConfig.SourceCode.GithubEnterprise.SpaceLevel.Space, + steps: []testCaseStep{ + { + dataSource: "", + provider: `github_enterprise { + namespace = "spacelift-ci-org" + }`, + attribute: testCaseStepAttribute{ + key: "github_enterprise.0.id", + value: testConfig.SourceCode.GithubEnterprise.Default.ID, + }, + }, + { + dataSource: "", + provider: `github_enterprise { + namespace = "spacelift-ci-org" + id = "` + testConfig.SourceCode.GithubEnterprise.SpaceLevel.ID + `" + }`, + attribute: testCaseStepAttribute{ + key: "github_enterprise.0.id", + value: testConfig.SourceCode.GithubEnterprise.SpaceLevel.ID, + }, + }, + { + dataSource: `data "spacelift_github_enterprise_integration" "test" { + id = "` + testConfig.SourceCode.GithubEnterprise.SpaceLevel.ID + `" + }`, + provider: `github_enterprise { + namespace = "spacelift-ci-org" + id = data.spacelift_github_enterprise_integration.test.id + }`, + attribute: testCaseStepAttribute{ + key: "github_enterprise.0.id", + value: testConfig.SourceCode.GithubEnterprise.SpaceLevel.ID, + }, + }, + { + dataSource: `data "spacelift_github_enterprise_integration" "test" {}`, + provider: `github_enterprise { + namespace = "spacelift-ci-org" + id = data.spacelift_github_enterprise_integration.test.id + }`, + attribute: testCaseStepAttribute{ + key: "github_enterprise.0.id", + value: testConfig.SourceCode.GithubEnterprise.Default.ID, + }, + }, + { + dataSource: "", + provider: `github_enterprise { + namespace = "spacelift-ci-org" + }`, + attribute: testCaseStepAttribute{ + key: "github_enterprise.0.id", + value: testConfig.SourceCode.GithubEnterprise.Default.ID, + }, + }, + }, + }, + // GitLab + { + name: "gitlab-with-changing-vcs-id-" + randomID(), + repository: "multimodule", + branch: "main", + space: testConfig.SourceCode.Gitlab.SpaceLevel.Space, + steps: []testCaseStep{ + { + dataSource: "", + provider: `gitlab { + namespace = "spacelift-ci" + }`, + attribute: testCaseStepAttribute{ + key: "gitlab.0.id", + value: testConfig.SourceCode.Gitlab.Default.ID, + }, + }, + { + dataSource: "", + provider: `gitlab { + namespace = "spacelift-ci" + id = "` + testConfig.SourceCode.Gitlab.SpaceLevel.ID + `" + }`, + attribute: testCaseStepAttribute{ + key: "gitlab.0.id", + value: testConfig.SourceCode.Gitlab.SpaceLevel.ID, + }, + }, + { + dataSource: `data "spacelift_gitlab_integration" "test" { + id = "` + testConfig.SourceCode.Gitlab.SpaceLevel.ID + `" + }`, + provider: `gitlab { + namespace = "spacelift-ci" + id = data.spacelift_gitlab_integration.test.id + }`, + attribute: testCaseStepAttribute{ + key: "gitlab.0.id", + value: testConfig.SourceCode.Gitlab.SpaceLevel.ID, + }, + }, + { + dataSource: `data "spacelift_gitlab_integration" "test" {}`, + provider: `gitlab { + namespace = "spacelift-ci" + id = data.spacelift_gitlab_integration.test.id + }`, + attribute: testCaseStepAttribute{ + key: "gitlab.0.id", + value: testConfig.SourceCode.Gitlab.Default.ID, + }, + }, + { + dataSource: "", + provider: `gitlab { + namespace = "spacelift-ci" + }`, + attribute: testCaseStepAttribute{ + key: "gitlab.0.id", + value: testConfig.SourceCode.Gitlab.Default.ID, + }, + }, + }, + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + var steps []resource.TestStep + for i := range tc.steps { + step := tc.steps[i] + steps = append(steps, resource.TestStep{ + Config: fmt.Sprintf(` + %s + + resource "`+resourceName+`" "test" { + name = "%s" + repository = "%s" + branch = "%s" + space_id = "%s" + administrative = false + %s + }`, step.dataSource, tc.name, tc.repository, tc.branch, tc.space, step.provider), + Check: Resource(resourceName+".test", Attribute(step.attribute.key, Equals(step.attribute.value))), + }) + } + + testSteps(t, steps) + }) + } + }) + + t.Run("mix providers", func(t *testing.T) { + testSteps(t, []resource.TestStep{ + { + Config: ` + resource "` + resourceName + `" "test" { + name = "mix-different-providers-` + randomID() + `" + repository = "spacelift-ci" + branch = "main" + space_id = "` + testConfig.SourceCode.AzureDevOps.SpaceLevel.Space + `" + administrative = false + azure_devops { + project = "spacelift-ci" + id = "` + testConfig.SourceCode.AzureDevOps.SpaceLevel.ID + `" + } + } + `, + Check: Resource(resourceName+".test", Attribute("azure_devops.0.id", Equals(testConfig.SourceCode.AzureDevOps.SpaceLevel.ID))), + }, + { + Config: ` + resource "` + resourceName + `" "test" { + name = "mix-different-providers-` + randomID() + `" + repository = "empty" + branch = "master" + space_id = "` + testConfig.SourceCode.BitbucketCloud.SpaceLevel.Space + `" + administrative = false + bitbucket_cloud { + namespace = "thespacelift" + id = "` + testConfig.SourceCode.BitbucketCloud.SpaceLevel.ID + `" + } + } + `, + Check: Resource(resourceName+".test", Attribute("bitbucket_cloud.0.id", Equals(testConfig.SourceCode.BitbucketCloud.SpaceLevel.ID))), + }, + { + Config: ` + resource "` + resourceName + `" "test" { + name = "mix-different-providers-` + randomID() + `" + repository = "tfprovider-test" + branch = "master" + space_id = "` + testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.Space + `" + administrative = false + bitbucket_datacenter { + namespace = "E2E" + id = "` + testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.ID + `" + } + } + `, + Check: Resource(resourceName+".test", Attribute("bitbucket_datacenter.0.id", Equals(testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.ID))), + }, + { + Config: ` + resource "` + resourceName + `" "test" { + name = "mix-different-providers-` + randomID() + `" + repository = "empty" + branch = "main" + space_id = "` + testConfig.SourceCode.GithubEnterprise.SpaceLevel.Space + `" + administrative = false + github_enterprise { + namespace = "spacelift-ci-org" + id = "` + testConfig.SourceCode.GithubEnterprise.SpaceLevel.ID + `" + } + } + `, + Check: Resource(resourceName+".test", Attribute("github_enterprise.0.id", Equals(testConfig.SourceCode.GithubEnterprise.SpaceLevel.ID))), + }, + { + Config: ` + resource "` + resourceName + `" "test" { + name = "mix-different-providers-` + randomID() + `" + repository = "multimodule" + branch = "main" + space_id = "` + testConfig.SourceCode.Gitlab.SpaceLevel.Space + `" + administrative = false + gitlab { + namespace = "spacelift-ci" + id = "` + testConfig.SourceCode.Gitlab.SpaceLevel.ID + `" + } + } + `, + Check: Resource(resourceName+".test", Attribute("gitlab.0.id", Equals(testConfig.SourceCode.Gitlab.SpaceLevel.ID))), + }, + { + Config: ` + data "spacelift_azure_devops_integration" "test" {} + + resource "` + resourceName + `" "test" { + name = "mix-different-providers-` + randomID() + `" + repository = "spacelift-ci" + branch = "main" + space_id = "` + testConfig.SourceCode.AzureDevOps.SpaceLevel.Space + `" + administrative = false + azure_devops { + project = "spacelift-ci" + id = data.spacelift_azure_devops_integration.test.id + } + } + `, + Check: Resource(resourceName+".test", Attribute("azure_devops.0.id", Equals(testConfig.SourceCode.AzureDevOps.Default.ID))), + }, + { + Config: ` + data "spacelift_bitbucket_cloud_integration" "test" {} + + resource "` + resourceName + `" "test" { + name = "mix-different-providers-` + randomID() + `" + repository = "empty" + branch = "master" + space_id = "` + testConfig.SourceCode.BitbucketCloud.SpaceLevel.Space + `" + administrative = false + bitbucket_cloud { + namespace = "thespacelift" + id = data.spacelift_bitbucket_cloud_integration.test.id + } + } + `, + Check: Resource(resourceName+".test", Attribute("bitbucket_cloud.0.id", Equals(testConfig.SourceCode.BitbucketCloud.Default.ID))), + }, + { + Config: ` + data "spacelift_bitbucket_datacenter_integration" "test" {} + + resource "` + resourceName + `" "test" { + name = "mix-different-providers-` + randomID() + `" + repository = "tfprovider-test" + branch = "master" + space_id = "` + testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.Space + `" + administrative = false + bitbucket_datacenter { + namespace = "E2E" + id = data.spacelift_bitbucket_datacenter_integration.test.id + } + } + `, + Check: Resource(resourceName+".test", Attribute("bitbucket_datacenter.0.id", Equals(testConfig.SourceCode.BitbucketDatacenter.Default.ID))), + }, + { + Config: ` + data "spacelift_github_enterprise_integration" "test" {} + + resource "` + resourceName + `" "test" { + name = "mix-different-providers-` + randomID() + `" + repository = "empty" + branch = "main" + space_id = "` + testConfig.SourceCode.GithubEnterprise.SpaceLevel.Space + `" + administrative = false + github_enterprise { + namespace = "spacelift-ci-org" + id = data.spacelift_github_enterprise_integration.test.id + } + } + `, + Check: Resource(resourceName+".test", Attribute("github_enterprise.0.id", Equals(testConfig.SourceCode.GithubEnterprise.Default.ID))), + }, + { + Config: ` + data "spacelift_gitlab_integration" "test" {} + + resource "` + resourceName + `" "test" { + name = "mix-different-providers-` + randomID() + `" + repository = "multimodule" + branch = "main" + space_id = "` + testConfig.SourceCode.Gitlab.SpaceLevel.Space + `" + administrative = false + gitlab { + namespace = "spacelift-ci" + id = data.spacelift_gitlab_integration.test.id + } + } + `, + Check: Resource(resourceName+".test", Attribute("gitlab.0.id", Equals(testConfig.SourceCode.Gitlab.Default.ID))), + }, + }) + }) + }) + } +} From 85e106096d658ed596d22b7a2757847ab4efd70b Mon Sep 17 00:00:00 2001 From: Piotr Truszkowski Date: Thu, 29 Feb 2024 09:21:25 +0100 Subject: [PATCH 2/2] more values into testConfig --- .github/workflows/test-prod.yml | 15 ++ .github/workflows/test.yml | 15 ++ spacelift/config_test.go | 25 +++ spacelift/vcs_integration_test.go | 344 +++++++++++++++--------------- 4 files changed, 226 insertions(+), 173 deletions(-) diff --git a/.github/workflows/test-prod.yml b/.github/workflows/test-prod.yml index 5d925b27..a61b9056 100644 --- a/.github/workflows/test-prod.yml +++ b/.github/workflows/test-prod.yml @@ -91,3 +91,18 @@ jobs: SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_APIHOST: "https://gitlab.com" SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKSECRET: ${{ secrets.PROD_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKSECRET }} SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKURL: ${{ secrets.PROD_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKURL }} + SPACELIFT_PROVIDER_TEST_SOURCECODE_AZUREDEVOPS_REPOSITORY_NAME: "spacelift-ci" + SPACELIFT_PROVIDER_TEST_SOURCECODE_AZUREDEVOPS_REPOSITORY_NAMESPACE: "spacelift-ci" + SPACELIFT_PROVIDER_TEST_SOURCECODE_AZUREDEVOPS_REPOSITORY_BRANCH: "main" + SPACELIFT_PROVIDER_TEST_SOURCECODE_BITBUCKETCLOUD_REPOSITORY_NAME: "empty" + SPACELIFT_PROVIDER_TEST_SOURCECODE_BITBUCKETCLOUD_REPOSITORY_NAMESPACE: "thespacelift" + SPACELIFT_PROVIDER_TEST_SOURCECODE_BITBUCKETCLOUD_REPOSITORY_BRANCH: "master" + SPACELIFT_PROVIDER_TEST_SOURCECODE_BITBUCKETDATACENTER_REPOSITORY_NAME: "tfprovider-test" + SPACELIFT_PROVIDER_TEST_SOURCECODE_BITBUCKETDATACENTER_REPOSITORY_NAMESPACE: "E2E" + SPACELIFT_PROVIDER_TEST_SOURCECODE_BITBUCKETDATACENTER_REPOSITORY_BRANCH: "master" + SPACELIFT_PROVIDER_TEST_SOURCECODE_GITHUBENTERPRISE_REPOSITORY_NAME: "empty" + SPACELIFT_PROVIDER_TEST_SOURCECODE_GITHUBENTERPRISE_REPOSITORY_NAMESPACE: "spacelift-ci-org" + SPACELIFT_PROVIDER_TEST_SOURCECODE_GITHUBENTERPRISE_REPOSITORY_BRANCH: "main" + SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_REPOSITORY_NAME: "multimodule" + SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_REPOSITORY_NAMESPACE: "spacelift-ci" + SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_REPOSITORY_BRANCH: "main" \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 59952053..a425c81e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -93,3 +93,18 @@ jobs: SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_APIHOST: "https://gitlab.com" SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKSECRET: ${{ secrets.PREPROD_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKSECRET }} SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKURL: ${{ secrets.PREPROD_SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_SPACELEVEL_WEBHOOKURL }} + SPACELIFT_PROVIDER_TEST_SOURCECODE_AZUREDEVOPS_REPOSITORY_NAME: "spacelift-ci" + SPACELIFT_PROVIDER_TEST_SOURCECODE_AZUREDEVOPS_REPOSITORY_NAMESPACE: "spacelift-ci" + SPACELIFT_PROVIDER_TEST_SOURCECODE_AZUREDEVOPS_REPOSITORY_BRANCH: "main" + SPACELIFT_PROVIDER_TEST_SOURCECODE_BITBUCKETCLOUD_REPOSITORY_NAME: "empty" + SPACELIFT_PROVIDER_TEST_SOURCECODE_BITBUCKETCLOUD_REPOSITORY_NAMESPACE: "thespacelift" + SPACELIFT_PROVIDER_TEST_SOURCECODE_BITBUCKETCLOUD_REPOSITORY_BRANCH: "master" + SPACELIFT_PROVIDER_TEST_SOURCECODE_BITBUCKETDATACENTER_REPOSITORY_NAME: "tfprovider-test" + SPACELIFT_PROVIDER_TEST_SOURCECODE_BITBUCKETDATACENTER_REPOSITORY_NAMESPACE: "E2E" + SPACELIFT_PROVIDER_TEST_SOURCECODE_BITBUCKETDATACENTER_REPOSITORY_BRANCH: "master" + SPACELIFT_PROVIDER_TEST_SOURCECODE_GITHUBENTERPRISE_REPOSITORY_NAME: "empty" + SPACELIFT_PROVIDER_TEST_SOURCECODE_GITHUBENTERPRISE_REPOSITORY_NAMESPACE: "spacelift-ci-org" + SPACELIFT_PROVIDER_TEST_SOURCECODE_GITHUBENTERPRISE_REPOSITORY_BRANCH: "main" + SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_REPOSITORY_NAME: "multimodule" + SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_REPOSITORY_NAMESPACE: "spacelift-ci" + SPACELIFT_PROVIDER_TEST_SOURCECODE_GITLAB_REPOSITORY_BRANCH: "main" \ No newline at end of file diff --git a/spacelift/config_test.go b/spacelift/config_test.go index ed6eb605..3b1af9eb 100644 --- a/spacelift/config_test.go +++ b/spacelift/config_test.go @@ -27,6 +27,11 @@ var testConfig struct { WebhookSecret string WebhookURL string } + Repository struct { + Name string + Namespace string + Branch string + } } BitbucketCloud struct { Default struct { @@ -42,6 +47,11 @@ var testConfig struct { Username string WebhookURL string } + Repository struct { + Name string + Namespace string + Branch string + } } BitbucketDatacenter struct { Default struct { @@ -63,6 +73,11 @@ var testConfig struct { WebhookSecret string WebhookURL string } + Repository struct { + Name string + Namespace string + Branch string + } } GithubEnterprise struct { Default struct { @@ -82,6 +97,11 @@ var testConfig struct { WebhookSecret string WebhookURL string } + Repository struct { + Name string + Namespace string + Branch string + } } Gitlab struct { Default struct { @@ -99,6 +119,11 @@ var testConfig struct { WebhookSecret string WebhookURL string } + Repository struct { + Name string + Namespace string + Branch string + } } } } diff --git a/spacelift/vcs_integration_test.go b/spacelift/vcs_integration_test.go index 1c50e87e..69219911 100644 --- a/spacelift/vcs_integration_test.go +++ b/spacelift/vcs_integration_test.go @@ -32,22 +32,22 @@ func TestVCSIntegration(t *testing.T) { // Azure Dev Ops { name: "azure-devops-with-non-specified-integration-" + randomID(), - repository: "spacelift-ci", - branch: "main", + repository: testConfig.SourceCode.AzureDevOps.Repository.Name, + branch: testConfig.SourceCode.AzureDevOps.Repository.Branch, space: "root", provider: `azure_devops { - project = "spacelift-ci" + project = "` + testConfig.SourceCode.AzureDevOps.Repository.Namespace + `" }`, attribute: "azure_devops.0.id", attributeValue: testConfig.SourceCode.AzureDevOps.Default.ID, }, { name: "azure-devops-with-an-empty-integration-id-" + randomID(), - repository: "spacelift-ci", - branch: "main", + repository: testConfig.SourceCode.AzureDevOps.Repository.Name, + branch: testConfig.SourceCode.AzureDevOps.Repository.Branch, space: "root", provider: `azure_devops { - project = "spacelift-ci" + project = "` + testConfig.SourceCode.AzureDevOps.Repository.Namespace + `" id = "" }`, attribute: "azure_devops.0.id", @@ -55,11 +55,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "azure-devops-with-default-integration-" + randomID(), - repository: "spacelift-ci", - branch: "main", + repository: testConfig.SourceCode.AzureDevOps.Repository.Name, + branch: testConfig.SourceCode.AzureDevOps.Repository.Branch, space: "root", provider: `azure_devops { - project = "spacelift-ci" + project = "` + testConfig.SourceCode.AzureDevOps.Repository.Namespace + `" id = "` + testConfig.SourceCode.AzureDevOps.Default.ID + `" }`, attribute: "azure_devops.0.id", @@ -67,11 +67,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "azure-devops-with-space-level-integration-" + randomID(), - repository: "spacelift-ci", - branch: "main", + repository: testConfig.SourceCode.AzureDevOps.Repository.Name, + branch: testConfig.SourceCode.AzureDevOps.Repository.Branch, space: testConfig.SourceCode.AzureDevOps.SpaceLevel.Space, provider: `azure_devops { - project = "spacelift-ci" + project = "` + testConfig.SourceCode.AzureDevOps.Repository.Namespace + `" id = "` + testConfig.SourceCode.AzureDevOps.SpaceLevel.ID + `" }`, attribute: "azure_devops.0.id", @@ -79,11 +79,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "azure-devops-with-default-integration-from-data-source-" + randomID(), - repository: "spacelift-ci", - branch: "main", + repository: testConfig.SourceCode.AzureDevOps.Repository.Name, + branch: testConfig.SourceCode.AzureDevOps.Repository.Branch, space: "root", provider: `azure_devops { - project = "spacelift-ci" + project = "` + testConfig.SourceCode.AzureDevOps.Repository.Namespace + `" id = data.spacelift_azure_devops_integration.test.id }`, dataSource: `data "spacelift_azure_devops_integration" "test" {}`, @@ -92,11 +92,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "azure-devops-with-space-level-integration-from-data-source-" + randomID(), - repository: "spacelift-ci", - branch: "main", + repository: testConfig.SourceCode.AzureDevOps.Repository.Name, + branch: testConfig.SourceCode.AzureDevOps.Repository.Branch, space: testConfig.SourceCode.AzureDevOps.SpaceLevel.Space, provider: `azure_devops { - project = "spacelift-ci" + project = "` + testConfig.SourceCode.AzureDevOps.Repository.Namespace + `" id = data.spacelift_azure_devops_integration.test.id }`, dataSource: `data "spacelift_azure_devops_integration" "test" { @@ -108,22 +108,22 @@ func TestVCSIntegration(t *testing.T) { // Bitbucket Cloud { name: "bitbucket-cloud-with-non-specified-integration-" + randomID(), - repository: "empty", - branch: "master", + repository: testConfig.SourceCode.BitbucketCloud.Repository.Name, + branch: testConfig.SourceCode.BitbucketCloud.Repository.Branch, space: "root", provider: `bitbucket_cloud { - namespace = "thespacelift" + namespace = "` + testConfig.SourceCode.BitbucketCloud.Repository.Namespace + `" }`, attribute: "bitbucket_cloud.0.id", attributeValue: testConfig.SourceCode.BitbucketCloud.Default.ID, }, { name: "bitbucket-cloud-with-an-empty-integration-id-" + randomID(), - repository: "empty", - branch: "master", + repository: testConfig.SourceCode.BitbucketCloud.Repository.Name, + branch: testConfig.SourceCode.BitbucketCloud.Repository.Branch, space: "root", provider: `bitbucket_cloud { - namespace = "thespacelift" + namespace = "` + testConfig.SourceCode.BitbucketCloud.Repository.Namespace + `" id = "" }`, attribute: "bitbucket_cloud.0.id", @@ -131,11 +131,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "bitbucket-cloud-with-default-integration-" + randomID(), - repository: "empty", - branch: "master", + repository: testConfig.SourceCode.BitbucketCloud.Repository.Name, + branch: testConfig.SourceCode.BitbucketCloud.Repository.Branch, space: "root", provider: `bitbucket_cloud { - namespace = "thespacelift" + namespace = "` + testConfig.SourceCode.BitbucketCloud.Repository.Namespace + `" id = "` + testConfig.SourceCode.BitbucketCloud.Default.ID + `" }`, attribute: "bitbucket_cloud.0.id", @@ -143,11 +143,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "bitbucket-cloud-with-space-level-integration-" + randomID(), - repository: "empty", - branch: "master", + repository: testConfig.SourceCode.BitbucketCloud.Repository.Name, + branch: testConfig.SourceCode.BitbucketCloud.Repository.Branch, space: testConfig.SourceCode.BitbucketCloud.SpaceLevel.Space, provider: `bitbucket_cloud { - namespace = "thespacelift" + namespace = "` + testConfig.SourceCode.BitbucketCloud.Repository.Namespace + `" id = "` + testConfig.SourceCode.BitbucketCloud.SpaceLevel.ID + `" }`, attribute: "bitbucket_cloud.0.id", @@ -155,11 +155,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "bitbucket-cloud-with-default-integration-from-data-source-" + randomID(), - repository: "empty", - branch: "master", + repository: testConfig.SourceCode.BitbucketCloud.Repository.Name, + branch: testConfig.SourceCode.BitbucketCloud.Repository.Branch, space: "root", provider: `bitbucket_cloud { - namespace = "thespacelift" + namespace = "` + testConfig.SourceCode.BitbucketCloud.Repository.Namespace + `" id = data.spacelift_bitbucket_cloud_integration.test.id }`, dataSource: `data "spacelift_bitbucket_cloud_integration" "test" {}`, @@ -168,11 +168,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "bitbucket-cloud-with-space-level-integration-from-data-source-" + randomID(), - repository: "empty", - branch: "master", + repository: testConfig.SourceCode.BitbucketCloud.Repository.Name, + branch: testConfig.SourceCode.BitbucketCloud.Repository.Branch, space: testConfig.SourceCode.BitbucketCloud.SpaceLevel.Space, provider: `bitbucket_cloud { - namespace = "thespacelift" + namespace = "` + testConfig.SourceCode.BitbucketCloud.Repository.Namespace + `" id = data.spacelift_bitbucket_cloud_integration.test.id }`, dataSource: `data "spacelift_bitbucket_cloud_integration" "test" { @@ -184,22 +184,22 @@ func TestVCSIntegration(t *testing.T) { // Bitbucket Datacenter { name: "bitbucket-datacenter-with-non-specified-integration-" + randomID(), - repository: "tfprovider-test", - branch: "master", + repository: testConfig.SourceCode.BitbucketDatacenter.Repository.Name, + branch: testConfig.SourceCode.BitbucketDatacenter.Repository.Branch, space: "root", provider: `bitbucket_datacenter { - namespace = "E2E" + namespace = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Namespace + `" }`, attribute: "bitbucket_datacenter.0.id", attributeValue: testConfig.SourceCode.BitbucketDatacenter.Default.ID, }, { name: "bitbucket-datacenter-with-an-empty-integration-id-" + randomID(), - repository: "tfprovider-test", - branch: "master", + repository: testConfig.SourceCode.BitbucketDatacenter.Repository.Name, + branch: testConfig.SourceCode.BitbucketDatacenter.Repository.Branch, space: "root", provider: `bitbucket_datacenter { - namespace = "E2E" + namespace = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Namespace + `" id = "" }`, attribute: "bitbucket_datacenter.0.id", @@ -207,11 +207,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "bitbucket-datacenter-with-default-integration-" + randomID(), - repository: "tfprovider-test", - branch: "master", + repository: testConfig.SourceCode.BitbucketDatacenter.Repository.Name, + branch: testConfig.SourceCode.BitbucketDatacenter.Repository.Branch, space: "root", provider: `bitbucket_datacenter { - namespace = "E2E" + namespace = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Namespace + `" id = "` + testConfig.SourceCode.BitbucketDatacenter.Default.ID + `" }`, attribute: "bitbucket_datacenter.0.id", @@ -219,11 +219,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "bitbucket-datacenter-with-space-level-integration-" + randomID(), - repository: "tfprovider-test", - branch: "master", + repository: testConfig.SourceCode.BitbucketDatacenter.Repository.Name, + branch: testConfig.SourceCode.BitbucketDatacenter.Repository.Branch, space: testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.Space, provider: `bitbucket_datacenter { - namespace = "E2E" + namespace = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Namespace + `" id = "` + testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.ID + `" }`, attribute: "bitbucket_datacenter.0.id", @@ -231,11 +231,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "bitbucket-datacenter-with-default-integration-from-data-source-" + randomID(), - repository: "tfprovider-test", - branch: "master", + repository: testConfig.SourceCode.BitbucketDatacenter.Repository.Name, + branch: testConfig.SourceCode.BitbucketDatacenter.Repository.Branch, space: "root", provider: `bitbucket_datacenter { - namespace = "E2E" + namespace = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Namespace + `" id = data.spacelift_bitbucket_datacenter_integration.test.id }`, dataSource: `data "spacelift_bitbucket_datacenter_integration" "test" {}`, @@ -244,11 +244,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "bitbucket-datacenter-with-space-level-integration-from-data-source-" + randomID(), - repository: "tfprovider-test", - branch: "master", + repository: testConfig.SourceCode.BitbucketDatacenter.Repository.Name, + branch: testConfig.SourceCode.BitbucketDatacenter.Repository.Branch, space: testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.Space, provider: `bitbucket_datacenter { - namespace = "E2E" + namespace = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Namespace + `" id = data.spacelift_bitbucket_datacenter_integration.test.id }`, dataSource: `data "spacelift_bitbucket_datacenter_integration" "test" { @@ -260,22 +260,22 @@ func TestVCSIntegration(t *testing.T) { // GitHub Enterprise { name: "github-with-non-specified-integration-" + randomID(), - repository: "empty", - branch: "main", + repository: testConfig.SourceCode.GithubEnterprise.Repository.Name, + branch: testConfig.SourceCode.GithubEnterprise.Repository.Branch, space: "root", provider: `github_enterprise { - namespace = "spacelift-ci-org" + namespace = "` + testConfig.SourceCode.GithubEnterprise.Repository.Namespace + `" }`, attribute: "github_enterprise.0.id", attributeValue: testConfig.SourceCode.GithubEnterprise.Default.ID, }, { name: "github-with-an-empty-integration-id-" + randomID(), - repository: "empty", - branch: "main", + repository: testConfig.SourceCode.GithubEnterprise.Repository.Name, + branch: testConfig.SourceCode.GithubEnterprise.Repository.Branch, space: "root", provider: `github_enterprise { - namespace = "spacelift-ci-org" + namespace = "` + testConfig.SourceCode.GithubEnterprise.Repository.Namespace + `" id = "" }`, attribute: "github_enterprise.0.id", @@ -283,11 +283,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "github-with-default-integration-" + randomID(), - repository: "empty", - branch: "main", + repository: testConfig.SourceCode.GithubEnterprise.Repository.Name, + branch: testConfig.SourceCode.GithubEnterprise.Repository.Branch, space: "root", provider: `github_enterprise { - namespace = "spacelift-ci-org" + namespace = "` + testConfig.SourceCode.GithubEnterprise.Repository.Namespace + `" id = "` + testConfig.SourceCode.GithubEnterprise.Default.ID + `" }`, attribute: "github_enterprise.0.id", @@ -295,11 +295,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "github-with-space-level-integration-" + randomID(), - repository: "empty", - branch: "main", + repository: testConfig.SourceCode.GithubEnterprise.Repository.Name, + branch: testConfig.SourceCode.GithubEnterprise.Repository.Branch, space: testConfig.SourceCode.GithubEnterprise.SpaceLevel.Space, provider: `github_enterprise { - namespace = "spacelift-ci-org" + namespace = "` + testConfig.SourceCode.GithubEnterprise.Repository.Namespace + `" id = "` + testConfig.SourceCode.GithubEnterprise.SpaceLevel.ID + `" }`, attribute: "github_enterprise.0.id", @@ -307,11 +307,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "github-with-default-integration-from-data-source-" + randomID(), - repository: "empty", - branch: "main", + repository: testConfig.SourceCode.GithubEnterprise.Repository.Name, + branch: testConfig.SourceCode.GithubEnterprise.Repository.Branch, space: "root", provider: `github_enterprise { - namespace = "spacelift-ci-org" + namespace = "` + testConfig.SourceCode.GithubEnterprise.Repository.Namespace + `" id = data.spacelift_github_enterprise_integration.test.id }`, dataSource: `data "spacelift_github_enterprise_integration" "test" {}`, @@ -320,11 +320,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "github-with-space-level-integration-from-data-source-" + randomID(), - repository: "empty", - branch: "main", + repository: testConfig.SourceCode.GithubEnterprise.Repository.Name, + branch: testConfig.SourceCode.GithubEnterprise.Repository.Branch, space: testConfig.SourceCode.GithubEnterprise.SpaceLevel.Space, provider: `github_enterprise { - namespace = "spacelift-ci-org" + namespace = "` + testConfig.SourceCode.GithubEnterprise.Repository.Namespace + `" id = data.spacelift_github_enterprise_integration.test.id }`, dataSource: `data "spacelift_github_enterprise_integration" "test" { @@ -336,22 +336,22 @@ func TestVCSIntegration(t *testing.T) { // GitLab { name: "gitlab-with-non-specified-integration-" + randomID(), - repository: "multimodule", - branch: "main", + repository: testConfig.SourceCode.Gitlab.Repository.Name, + branch: testConfig.SourceCode.Gitlab.Repository.Branch, space: "root", provider: `gitlab { - namespace = "spacelift-ci" + namespace = "` + testConfig.SourceCode.Gitlab.Repository.Namespace + `" }`, attribute: "gitlab.0.id", attributeValue: testConfig.SourceCode.Gitlab.Default.ID, }, { name: "gitlab-with-an-empty-integration-id-" + randomID(), - repository: "multimodule", - branch: "main", + repository: testConfig.SourceCode.Gitlab.Repository.Name, + branch: testConfig.SourceCode.Gitlab.Repository.Branch, space: "root", provider: `gitlab { - namespace = "spacelift-ci" + namespace = "` + testConfig.SourceCode.Gitlab.Repository.Namespace + `" id = "" }`, attribute: "gitlab.0.id", @@ -359,11 +359,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "gitlab-with-default-integration-" + randomID(), - repository: "multimodule", - branch: "main", + repository: testConfig.SourceCode.Gitlab.Repository.Name, + branch: testConfig.SourceCode.Gitlab.Repository.Branch, space: "root", provider: `gitlab { - namespace = "spacelift-ci" + namespace = "` + testConfig.SourceCode.Gitlab.Repository.Namespace + `" id = "` + testConfig.SourceCode.Gitlab.Default.ID + `" }`, attribute: "gitlab.0.id", @@ -371,11 +371,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "gitlab-with-space-level-integration-" + randomID(), - repository: "multimodule", - branch: "main", + repository: testConfig.SourceCode.Gitlab.Repository.Name, + branch: testConfig.SourceCode.Gitlab.Repository.Branch, space: testConfig.SourceCode.Gitlab.SpaceLevel.Space, provider: `gitlab { - namespace = "spacelift-ci" + namespace = "` + testConfig.SourceCode.Gitlab.Repository.Namespace + `" id = "` + testConfig.SourceCode.Gitlab.SpaceLevel.ID + `" }`, attribute: "gitlab.0.id", @@ -383,11 +383,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "gitlab-with-default-integration-from-data-source-" + randomID(), - repository: "multimodule", - branch: "main", + repository: testConfig.SourceCode.Gitlab.Repository.Name, + branch: testConfig.SourceCode.Gitlab.Repository.Branch, space: "root", provider: `gitlab { - namespace = "spacelift-ci" + namespace = "` + testConfig.SourceCode.Gitlab.Repository.Namespace + `" id = data.spacelift_gitlab_integration.test.id }`, dataSource: `data "spacelift_gitlab_integration" "test" {}`, @@ -396,11 +396,11 @@ func TestVCSIntegration(t *testing.T) { }, { name: "gitlab-with-space-level-integration-from-data-source-" + randomID(), - repository: "multimodule", - branch: "main", + repository: testConfig.SourceCode.Gitlab.Repository.Name, + branch: testConfig.SourceCode.Gitlab.Repository.Branch, space: testConfig.SourceCode.Gitlab.SpaceLevel.Space, provider: `gitlab { - namespace = "spacelift-ci" + namespace = "` + testConfig.SourceCode.Gitlab.Repository.Namespace + `" id = data.spacelift_gitlab_integration.test.id }`, dataSource: `data "spacelift_gitlab_integration" "test" { @@ -414,17 +414,16 @@ func TestVCSIntegration(t *testing.T) { for _, tc := range testCases { tc := tc t.Run(tc.name, func(t *testing.T) { - config := fmt.Sprintf(` - %s + config := tc.dataSource + ` - resource "`+resourceName+`" "test" { - name = "%s" - repository = "%s" - branch = "%s" - space_id = "%s" + resource "` + resourceName + `" "test" { + name = "` + tc.name + `" + repository = "` + tc.repository + `" + branch = "` + tc.branch + `" + space_id = "` + tc.space + `" administrative = false - %s - }`, tc.dataSource, tc.name, tc.repository, tc.branch, tc.space, tc.provider) + ` + tc.provider + ` + }` var tfstateSerial int64 testSteps(t, []resource.TestStep{ @@ -472,14 +471,14 @@ func TestVCSIntegration(t *testing.T) { // Azure Dev Ops { name: "azure-devops-with-changing-vcs-id-" + randomID(), - repository: "spacelift-ci", - branch: "main", + repository: testConfig.SourceCode.AzureDevOps.Repository.Name, + branch: testConfig.SourceCode.AzureDevOps.Repository.Branch, space: testConfig.SourceCode.AzureDevOps.SpaceLevel.Space, steps: []testCaseStep{ { dataSource: "", provider: `azure_devops { - project = "spacelift-ci" + project = "` + testConfig.SourceCode.AzureDevOps.Repository.Namespace + `" }`, attribute: testCaseStepAttribute{ key: "azure_devops.0.id", @@ -489,7 +488,7 @@ func TestVCSIntegration(t *testing.T) { { dataSource: "", provider: `azure_devops { - project = "spacelift-ci" + project = "` + testConfig.SourceCode.AzureDevOps.Repository.Namespace + `" id = "` + testConfig.SourceCode.AzureDevOps.SpaceLevel.ID + `" }`, attribute: testCaseStepAttribute{ @@ -502,7 +501,7 @@ func TestVCSIntegration(t *testing.T) { id = "` + testConfig.SourceCode.AzureDevOps.SpaceLevel.ID + `" }`, provider: `azure_devops { - project = "spacelift-ci" + project = "` + testConfig.SourceCode.AzureDevOps.Repository.Namespace + `" id = data.spacelift_azure_devops_integration.test.id }`, attribute: testCaseStepAttribute{ @@ -513,7 +512,7 @@ func TestVCSIntegration(t *testing.T) { { dataSource: `data "spacelift_azure_devops_integration" "test" {}`, provider: `azure_devops { - project = "spacelift-ci" + project = "` + testConfig.SourceCode.AzureDevOps.Repository.Namespace + `" id = data.spacelift_azure_devops_integration.test.id }`, attribute: testCaseStepAttribute{ @@ -524,7 +523,7 @@ func TestVCSIntegration(t *testing.T) { { dataSource: "", provider: `azure_devops { - project = "spacelift-ci" + project = "` + testConfig.SourceCode.AzureDevOps.Repository.Namespace + `" }`, attribute: testCaseStepAttribute{ key: "azure_devops.0.id", @@ -536,14 +535,14 @@ func TestVCSIntegration(t *testing.T) { // Bitbucket Cloud { name: "bitbucket-cloud-with-changing-vcs-id-" + randomID(), - repository: "empty", - branch: "master", + repository: testConfig.SourceCode.BitbucketCloud.Repository.Name, + branch: testConfig.SourceCode.BitbucketCloud.Repository.Branch, space: testConfig.SourceCode.BitbucketCloud.SpaceLevel.Space, steps: []testCaseStep{ { dataSource: "", provider: `bitbucket_cloud { - namespace = "thespacelift" + namespace = "` + testConfig.SourceCode.BitbucketCloud.Repository.Namespace + `" }`, attribute: testCaseStepAttribute{ key: "bitbucket_cloud.0.id", @@ -553,7 +552,7 @@ func TestVCSIntegration(t *testing.T) { { dataSource: "", provider: `bitbucket_cloud { - namespace = "thespacelift" + namespace = "` + testConfig.SourceCode.BitbucketCloud.Repository.Namespace + `" id = "` + testConfig.SourceCode.BitbucketCloud.SpaceLevel.ID + `" }`, attribute: testCaseStepAttribute{ @@ -566,7 +565,7 @@ func TestVCSIntegration(t *testing.T) { id = "` + testConfig.SourceCode.BitbucketCloud.SpaceLevel.ID + `" }`, provider: `bitbucket_cloud { - namespace = "thespacelift" + namespace = "` + testConfig.SourceCode.BitbucketCloud.Repository.Namespace + `" id = data.spacelift_bitbucket_cloud_integration.test.id }`, attribute: testCaseStepAttribute{ @@ -577,7 +576,7 @@ func TestVCSIntegration(t *testing.T) { { dataSource: `data "spacelift_bitbucket_cloud_integration" "test" {}`, provider: `bitbucket_cloud { - namespace = "thespacelift" + namespace = "` + testConfig.SourceCode.BitbucketCloud.Repository.Namespace + `" id = data.spacelift_bitbucket_cloud_integration.test.id }`, attribute: testCaseStepAttribute{ @@ -588,7 +587,7 @@ func TestVCSIntegration(t *testing.T) { { dataSource: "", provider: `bitbucket_cloud { - namespace = "thespacelift" + namespace = "` + testConfig.SourceCode.BitbucketCloud.Repository.Namespace + `" }`, attribute: testCaseStepAttribute{ key: "bitbucket_cloud.0.id", @@ -600,14 +599,14 @@ func TestVCSIntegration(t *testing.T) { // Bitbucket Datacenter { name: "bitbucket-datacenter-with-changing-vcs-id-" + randomID(), - repository: "tfprovider-test", - branch: "master", + repository: testConfig.SourceCode.BitbucketDatacenter.Repository.Name, + branch: testConfig.SourceCode.BitbucketDatacenter.Repository.Branch, space: testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.Space, steps: []testCaseStep{ { dataSource: "", provider: `bitbucket_datacenter { - namespace = "E2E" + namespace = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Namespace + `" }`, attribute: testCaseStepAttribute{ key: "bitbucket_datacenter.0.id", @@ -617,7 +616,7 @@ func TestVCSIntegration(t *testing.T) { { dataSource: "", provider: `bitbucket_datacenter { - namespace = "E2E" + namespace = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Namespace + `" id = "` + testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.ID + `" }`, attribute: testCaseStepAttribute{ @@ -630,7 +629,7 @@ func TestVCSIntegration(t *testing.T) { id = "` + testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.ID + `" }`, provider: `bitbucket_datacenter { - namespace = "E2E" + namespace = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Namespace + `" id = data.spacelift_bitbucket_datacenter_integration.test.id }`, attribute: testCaseStepAttribute{ @@ -641,7 +640,7 @@ func TestVCSIntegration(t *testing.T) { { dataSource: `data "spacelift_bitbucket_datacenter_integration" "test" {}`, provider: `bitbucket_datacenter { - namespace = "E2E" + namespace = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Namespace + `" id = data.spacelift_bitbucket_datacenter_integration.test.id }`, attribute: testCaseStepAttribute{ @@ -652,7 +651,7 @@ func TestVCSIntegration(t *testing.T) { { dataSource: "", provider: `bitbucket_datacenter { - namespace = "E2E" + namespace = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Namespace + `" }`, attribute: testCaseStepAttribute{ key: "bitbucket_datacenter.0.id", @@ -664,14 +663,14 @@ func TestVCSIntegration(t *testing.T) { // GitHub Enterprise { name: "github-enterprise-with-changing-vcs-id-" + randomID(), - repository: "empty", - branch: "main", + repository: testConfig.SourceCode.GithubEnterprise.Repository.Name, + branch: testConfig.SourceCode.GithubEnterprise.Repository.Branch, space: testConfig.SourceCode.GithubEnterprise.SpaceLevel.Space, steps: []testCaseStep{ { dataSource: "", provider: `github_enterprise { - namespace = "spacelift-ci-org" + namespace = "` + testConfig.SourceCode.GithubEnterprise.Repository.Namespace + `" }`, attribute: testCaseStepAttribute{ key: "github_enterprise.0.id", @@ -681,7 +680,7 @@ func TestVCSIntegration(t *testing.T) { { dataSource: "", provider: `github_enterprise { - namespace = "spacelift-ci-org" + namespace = "` + testConfig.SourceCode.GithubEnterprise.Repository.Namespace + `" id = "` + testConfig.SourceCode.GithubEnterprise.SpaceLevel.ID + `" }`, attribute: testCaseStepAttribute{ @@ -694,7 +693,7 @@ func TestVCSIntegration(t *testing.T) { id = "` + testConfig.SourceCode.GithubEnterprise.SpaceLevel.ID + `" }`, provider: `github_enterprise { - namespace = "spacelift-ci-org" + namespace = "` + testConfig.SourceCode.GithubEnterprise.Repository.Namespace + `" id = data.spacelift_github_enterprise_integration.test.id }`, attribute: testCaseStepAttribute{ @@ -705,7 +704,7 @@ func TestVCSIntegration(t *testing.T) { { dataSource: `data "spacelift_github_enterprise_integration" "test" {}`, provider: `github_enterprise { - namespace = "spacelift-ci-org" + namespace = "` + testConfig.SourceCode.GithubEnterprise.Repository.Namespace + `" id = data.spacelift_github_enterprise_integration.test.id }`, attribute: testCaseStepAttribute{ @@ -716,7 +715,7 @@ func TestVCSIntegration(t *testing.T) { { dataSource: "", provider: `github_enterprise { - namespace = "spacelift-ci-org" + namespace = "` + testConfig.SourceCode.GithubEnterprise.Repository.Namespace + `" }`, attribute: testCaseStepAttribute{ key: "github_enterprise.0.id", @@ -728,14 +727,14 @@ func TestVCSIntegration(t *testing.T) { // GitLab { name: "gitlab-with-changing-vcs-id-" + randomID(), - repository: "multimodule", - branch: "main", + repository: testConfig.SourceCode.Gitlab.Repository.Name, + branch: testConfig.SourceCode.Gitlab.Repository.Branch, space: testConfig.SourceCode.Gitlab.SpaceLevel.Space, steps: []testCaseStep{ { dataSource: "", provider: `gitlab { - namespace = "spacelift-ci" + namespace = "` + testConfig.SourceCode.Gitlab.Repository.Namespace + `" }`, attribute: testCaseStepAttribute{ key: "gitlab.0.id", @@ -745,7 +744,7 @@ func TestVCSIntegration(t *testing.T) { { dataSource: "", provider: `gitlab { - namespace = "spacelift-ci" + namespace = "` + testConfig.SourceCode.Gitlab.Repository.Namespace + `" id = "` + testConfig.SourceCode.Gitlab.SpaceLevel.ID + `" }`, attribute: testCaseStepAttribute{ @@ -758,7 +757,7 @@ func TestVCSIntegration(t *testing.T) { id = "` + testConfig.SourceCode.Gitlab.SpaceLevel.ID + `" }`, provider: `gitlab { - namespace = "spacelift-ci" + namespace = "` + testConfig.SourceCode.Gitlab.Repository.Namespace + `" id = data.spacelift_gitlab_integration.test.id }`, attribute: testCaseStepAttribute{ @@ -769,7 +768,7 @@ func TestVCSIntegration(t *testing.T) { { dataSource: `data "spacelift_gitlab_integration" "test" {}`, provider: `gitlab { - namespace = "spacelift-ci" + namespace = "` + testConfig.SourceCode.Gitlab.Repository.Namespace + `" id = data.spacelift_gitlab_integration.test.id }`, attribute: testCaseStepAttribute{ @@ -780,7 +779,7 @@ func TestVCSIntegration(t *testing.T) { { dataSource: "", provider: `gitlab { - namespace = "spacelift-ci" + namespace = "` + testConfig.SourceCode.Gitlab.Repository.Namespace + `" }`, attribute: testCaseStepAttribute{ key: "gitlab.0.id", @@ -798,17 +797,16 @@ func TestVCSIntegration(t *testing.T) { for i := range tc.steps { step := tc.steps[i] steps = append(steps, resource.TestStep{ - Config: fmt.Sprintf(` - %s + Config: step.dataSource + ` - resource "`+resourceName+`" "test" { - name = "%s" - repository = "%s" - branch = "%s" - space_id = "%s" + resource "` + resourceName + `" "test" { + name = "` + tc.name + `" + repository = "` + tc.repository + `" + branch = "` + tc.branch + `" + space_id = "` + tc.space + `" administrative = false - %s - }`, step.dataSource, tc.name, tc.repository, tc.branch, tc.space, step.provider), + ` + step.provider + ` + }`, Check: Resource(resourceName+".test", Attribute(step.attribute.key, Equals(step.attribute.value))), }) } @@ -824,12 +822,12 @@ func TestVCSIntegration(t *testing.T) { Config: ` resource "` + resourceName + `" "test" { name = "mix-different-providers-` + randomID() + `" - repository = "spacelift-ci" - branch = "main" + repository = "` + testConfig.SourceCode.AzureDevOps.Repository.Name + `" + branch = "` + testConfig.SourceCode.AzureDevOps.Repository.Branch + `" space_id = "` + testConfig.SourceCode.AzureDevOps.SpaceLevel.Space + `" administrative = false azure_devops { - project = "spacelift-ci" + project = "` + testConfig.SourceCode.AzureDevOps.Repository.Namespace + `" id = "` + testConfig.SourceCode.AzureDevOps.SpaceLevel.ID + `" } } @@ -840,12 +838,12 @@ func TestVCSIntegration(t *testing.T) { Config: ` resource "` + resourceName + `" "test" { name = "mix-different-providers-` + randomID() + `" - repository = "empty" - branch = "master" + repository = "` + testConfig.SourceCode.BitbucketCloud.Repository.Name + `" + branch = "` + testConfig.SourceCode.BitbucketCloud.Repository.Branch + `" space_id = "` + testConfig.SourceCode.BitbucketCloud.SpaceLevel.Space + `" administrative = false bitbucket_cloud { - namespace = "thespacelift" + namespace = "` + testConfig.SourceCode.BitbucketCloud.Repository.Namespace + `" id = "` + testConfig.SourceCode.BitbucketCloud.SpaceLevel.ID + `" } } @@ -856,12 +854,12 @@ func TestVCSIntegration(t *testing.T) { Config: ` resource "` + resourceName + `" "test" { name = "mix-different-providers-` + randomID() + `" - repository = "tfprovider-test" - branch = "master" + repository = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Name + `" + branch = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Branch + `" space_id = "` + testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.Space + `" administrative = false bitbucket_datacenter { - namespace = "E2E" + namespace = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Namespace + `" id = "` + testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.ID + `" } } @@ -872,12 +870,12 @@ func TestVCSIntegration(t *testing.T) { Config: ` resource "` + resourceName + `" "test" { name = "mix-different-providers-` + randomID() + `" - repository = "empty" - branch = "main" + repository = "` + testConfig.SourceCode.GithubEnterprise.Repository.Name + `" + branch = "` + testConfig.SourceCode.GithubEnterprise.Repository.Branch + `" space_id = "` + testConfig.SourceCode.GithubEnterprise.SpaceLevel.Space + `" administrative = false github_enterprise { - namespace = "spacelift-ci-org" + namespace = "` + testConfig.SourceCode.GithubEnterprise.Repository.Namespace + `" id = "` + testConfig.SourceCode.GithubEnterprise.SpaceLevel.ID + `" } } @@ -888,12 +886,12 @@ func TestVCSIntegration(t *testing.T) { Config: ` resource "` + resourceName + `" "test" { name = "mix-different-providers-` + randomID() + `" - repository = "multimodule" - branch = "main" + repository = "` + testConfig.SourceCode.Gitlab.Repository.Name + `" + branch = "` + testConfig.SourceCode.Gitlab.Repository.Branch + `" space_id = "` + testConfig.SourceCode.Gitlab.SpaceLevel.Space + `" administrative = false gitlab { - namespace = "spacelift-ci" + namespace = "` + testConfig.SourceCode.Gitlab.Repository.Namespace + `" id = "` + testConfig.SourceCode.Gitlab.SpaceLevel.ID + `" } } @@ -906,12 +904,12 @@ func TestVCSIntegration(t *testing.T) { resource "` + resourceName + `" "test" { name = "mix-different-providers-` + randomID() + `" - repository = "spacelift-ci" - branch = "main" + repository = "` + testConfig.SourceCode.AzureDevOps.Repository.Name + `" + branch = "` + testConfig.SourceCode.AzureDevOps.Repository.Branch + `" space_id = "` + testConfig.SourceCode.AzureDevOps.SpaceLevel.Space + `" administrative = false azure_devops { - project = "spacelift-ci" + project = "` + testConfig.SourceCode.AzureDevOps.Repository.Namespace + `" id = data.spacelift_azure_devops_integration.test.id } } @@ -924,12 +922,12 @@ func TestVCSIntegration(t *testing.T) { resource "` + resourceName + `" "test" { name = "mix-different-providers-` + randomID() + `" - repository = "empty" - branch = "master" + repository = "` + testConfig.SourceCode.BitbucketCloud.Repository.Name + `" + branch = "` + testConfig.SourceCode.BitbucketCloud.Repository.Branch + `" space_id = "` + testConfig.SourceCode.BitbucketCloud.SpaceLevel.Space + `" administrative = false bitbucket_cloud { - namespace = "thespacelift" + namespace = "` + testConfig.SourceCode.BitbucketCloud.Repository.Namespace + `" id = data.spacelift_bitbucket_cloud_integration.test.id } } @@ -942,12 +940,12 @@ func TestVCSIntegration(t *testing.T) { resource "` + resourceName + `" "test" { name = "mix-different-providers-` + randomID() + `" - repository = "tfprovider-test" - branch = "master" + repository = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Name + `" + branch = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Branch + `" space_id = "` + testConfig.SourceCode.BitbucketDatacenter.SpaceLevel.Space + `" administrative = false bitbucket_datacenter { - namespace = "E2E" + namespace = "` + testConfig.SourceCode.BitbucketDatacenter.Repository.Namespace + `" id = data.spacelift_bitbucket_datacenter_integration.test.id } } @@ -960,12 +958,12 @@ func TestVCSIntegration(t *testing.T) { resource "` + resourceName + `" "test" { name = "mix-different-providers-` + randomID() + `" - repository = "empty" - branch = "main" + repository = "` + testConfig.SourceCode.GithubEnterprise.Repository.Name + `" + branch = "` + testConfig.SourceCode.GithubEnterprise.Repository.Branch + `" space_id = "` + testConfig.SourceCode.GithubEnterprise.SpaceLevel.Space + `" administrative = false github_enterprise { - namespace = "spacelift-ci-org" + namespace = "` + testConfig.SourceCode.GithubEnterprise.Repository.Namespace + `" id = data.spacelift_github_enterprise_integration.test.id } } @@ -978,12 +976,12 @@ func TestVCSIntegration(t *testing.T) { resource "` + resourceName + `" "test" { name = "mix-different-providers-` + randomID() + `" - repository = "multimodule" - branch = "main" + repository = "` + testConfig.SourceCode.Gitlab.Repository.Name + `" + branch = "` + testConfig.SourceCode.Gitlab.Repository.Branch + `" space_id = "` + testConfig.SourceCode.Gitlab.SpaceLevel.Space + `" administrative = false gitlab { - namespace = "spacelift-ci" + namespace = "` + testConfig.SourceCode.Gitlab.Repository.Namespace + `" id = data.spacelift_gitlab_integration.test.id } }