From 52cf5f059003722f63d16e21673be5a281f6ba83 Mon Sep 17 00:00:00 2001 From: Brett Wright Date: Mon, 22 Feb 2021 18:40:50 +0100 Subject: [PATCH 1/2] made sure that the replication_policy_id is set. --- provider/resource_replication.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/provider/resource_replication.go b/provider/resource_replication.go index 68d253f..5cd4248 100644 --- a/provider/resource_replication.go +++ b/provider/resource_replication.go @@ -45,7 +45,7 @@ func resourceReplication() *schema.Resource { Required: true, }, "replication_policy_id": { - Type: schema.TypeString, + Type: schema.TypeInt, Computed: true, }, "dest_namespace": { @@ -119,6 +119,7 @@ func resourceReplicationRead(d *schema.ResourceData, m interface{}) error { return fmt.Errorf("Resource not found %s", d.Id()) } + d.Set("replication_policy_id", jsonData.ID) return nil } From 9c7e0f41d5c5c39b2a47266aa02c5869ff6f8003 Mon Sep 17 00:00:00 2001 From: Brett Wright Date: Tue, 23 Feb 2021 13:16:16 +0100 Subject: [PATCH 2/2] fixed acc tests --- provider/resource_replication_test.go | 34 ++++----- provider/resource_retention_policy_test.go | 84 +++++++++++----------- 2 files changed, 55 insertions(+), 63 deletions(-) diff --git a/provider/resource_replication_test.go b/provider/resource_replication_test.go index 18e77fb..d4c9733 100644 --- a/provider/resource_replication_test.go +++ b/provider/resource_replication_test.go @@ -66,19 +66,17 @@ func testAccCheckReplicationDestroy(s *terraform.State) error { func testAccCheckReplicationBasic() string { endpoint := os.Getenv("HARBOR_REPLICATION_ENDPOINT") config := fmt.Sprintf(` - -resource "harbor_registry" "main" { - provider_name = "harbor" - name = "harbor-test-replication" - endpoint_url = "%s" - } - - resource "harbor_replication" "pull" { - name = "test_pull" - action = "pull" - registry_id = harbor_registry.main.registry_id - -}`, endpoint) + resource "harbor_registry" "main" { + provider_name = "harbor" + name = "harbor-test-replication" + endpoint_url = "%s" + } + + resource "harbor_replication" "pull" { + name = "test_pull" + action = "pull" + registry_id = harbor_registry.main.registry_id + }`, endpoint) return config } @@ -103,7 +101,6 @@ func testAccCheckReplicationUpdate() string { return config } - func TestDestinationNamespace(t *testing.T) { var scheduleType = "event_based" var destNamepace = "gcp-project" @@ -117,16 +114,16 @@ func TestDestinationNamespace(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckResourceExists(harborReplicationPull), resource.TestCheckResourceAttr( - resourceHarborRetentionMain, "schedule", scheduleType), + harborReplicationPull, "schedule", scheduleType), resource.TestCheckResourceAttr( - resourceHarborRetentionMain, "dest_namespace", scheduleType), + harborReplicationPull, "dest_namespace", destNamepace), ), }, }, }) } -func testReplicationPolicyDestinationNamespace(scheduleType, destNamepace string) string { +func testReplicationPolicyDestinationNamespace(scheduleType string, destNamepace string) string { endpoint := os.Getenv("HARBOR_REPLICATION_ENDPOINT") return fmt.Sprintf(` resource "harbor_registry" "main" { @@ -134,7 +131,7 @@ func testReplicationPolicyDestinationNamespace(scheduleType, destNamepace string name = "harbor-test" endpoint_url = "%s" } - + resource "harbor_replication" "pull" { name = "test_pull" action = "pull" @@ -144,4 +141,3 @@ func testReplicationPolicyDestinationNamespace(scheduleType, destNamepace string } `, endpoint, scheduleType, destNamepace) } - diff --git a/provider/resource_retention_policy_test.go b/provider/resource_retention_policy_test.go index e26c47e..2ae8fde 100644 --- a/provider/resource_retention_policy_test.go +++ b/provider/resource_retention_policy_test.go @@ -66,26 +66,23 @@ func TestAccRetentionUpdate(t *testing.T) { }) } -func TestDestinationNamespace(t *testing.T) { - var scheduleType = "event_based" - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - // CheckDestroy: testAccCheckLabelDestroy, - Steps: []resource.TestStep{ - { - Config: testReplicationPolicyDestinationNamespace(scheduleType), - Check: resource.ComposeTestCheckFunc( - testAccCheckResourceExists(resourceHarborRetentionMain), - resource.TestCheckResourceAttr( - resourceHarborRetentionMain, "schedule", scheduleType), - resource.TestCheckResourceAttr( - resourceHarborRetentionMain, "dest_namespace", scheduleType), - ), - }, - }, - }) -} +// func TestDestinationNamespace(t *testing.T) { +// resource.Test(t, resource.TestCase{ +// PreCheck: func() { testAccPreCheck(t) }, +// Providers: testAccProviders, +// // CheckDestroy: testAccCheckLabelDestroy, +// Steps: []resource.TestStep{ +// { +// Config: testReplicationPolicyDestinationNamespace(), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckResourceExists(resourceHarborRetentionMain), +// resource.TestCheckResourceAttr( +// resourceHarborRetentionMain, "schedule", scheduleType), +// ), +// }, +// }, +// }) +// } func testAccCheckRetentionBasic() string { return fmt.Sprintf(` @@ -111,27 +108,26 @@ func testAccCheckRetentionBasic() string { `) } -func testReplicationPolicyDestinationNamespace(scheduleType string) string { - return fmt.Sprintf(` - resource "harbor_project" "main" { - name = "acctest_retention_pol" - } - - resource "harbor_retention_policy" "main" { - scope = harbor_project.main.id - schedule = "event_base" - dest_namespace = "%s" - rule { - n_days_since_last_pull = 5 - repo_matching = "**" - tag_matching = "latest" - } - rule { - n_days_since_last_push = 10 - repo_matching = "**" - tag_matching = "latest" - } - - } - `, scheduleType) -} +// func testReplicationPolicyDestinationNamespace() string { +// return fmt.Sprintf(` +// resource "harbor_project" "main" { +// name = "acctest_retention_pol" +// } + +// resource "harbor_retention_policy" "main" { +// scope = harbor_project.main.id +// schedule = "event_base" +// rule { +// n_days_since_last_pull = 5 +// repo_matching = "**" +// tag_matching = "latest" +// } +// rule { +// n_days_since_last_push = 10 +// repo_matching = "**" +// tag_matching = "latest" +// } + +// } +// `) +// }