Skip to content

Commit

Permalink
fixed acc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wrighbr committed Feb 23, 2021
1 parent 52cf5f0 commit 9c7e0f4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 63 deletions.
34 changes: 15 additions & 19 deletions provider/resource_replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -103,7 +101,6 @@ func testAccCheckReplicationUpdate() string {
return config
}


func TestDestinationNamespace(t *testing.T) {
var scheduleType = "event_based"
var destNamepace = "gcp-project"
Expand All @@ -117,24 +114,24 @@ 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" {
provider_name = "harbor"
name = "harbor-test"
endpoint_url = "%s"
}
resource "harbor_replication" "pull" {
name = "test_pull"
action = "pull"
Expand All @@ -144,4 +141,3 @@ func testReplicationPolicyDestinationNamespace(scheduleType, destNamepace string
}
`, endpoint, scheduleType, destNamepace)
}

84 changes: 40 additions & 44 deletions provider/resource_retention_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand All @@ -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"
// }

// }
// `)
// }

0 comments on commit 9c7e0f4

Please sign in to comment.