Skip to content

Commit

Permalink
Merge pull request #114 from BESTSELLER/harbor_2.2_updates
Browse files Browse the repository at this point in the history
Harbor 2.2 updates
  • Loading branch information
wrighbr authored Apr 15, 2021
2 parents 7700960 + f0fd946 commit 0901cdb
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
name: Performaning Acceptance Test
command: |
source /tmp/secrets.env
TF_ACC=1 go test -v ./provider/ -count=1 -tags=external_auth
TF_ACC=1 go test -v ./... -count=1 -tags=external_auth
spellchecker:
docker:
Expand Down
22 changes: 22 additions & 0 deletions client/misc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package client

import (
"regexp"
"testing"
)

func TestGetSchedule(t *testing.T) {

schedule, cron := GetSchedule("hourly")

re := regexp.MustCompile(`([A-Z][^\s]*)`)
matched := re.MatchString(schedule)
if matched == false {
t.Error("Didn't return a Titled string")
}

matchCronStr := regexCron.MatchString(cron)
if matchCronStr == false {
t.Error("Invalid cron string")
}
}
9 changes: 1 addition & 8 deletions client/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@ func (client *Client) SetSchedule(d *schema.ResourceData, scheduleType string) (
return err
}

var jsonData models.SystemBody
err = json.Unmarshal([]byte(resp), &jsonData)
if err != nil {
return err
}

time := jsonData.Schedule.Type
requestType := "POST"
httpStatusCode := 201

if time != "" {
if resp != "" {
log.Printf("Schedule found performing PUT request")
requestType = "PUT"
httpStatusCode = 200
Expand Down
80 changes: 80 additions & 0 deletions provider/resource_garbage_collection_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// +build external_auth

package provider

import (
"fmt"
"testing"

"github.com/BESTSELLER/terraform-provider-harbor/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

const harborGCMain = "harbor_garbage_collection.main"

func testAccCheckGCDestroy(s *terraform.State) error {
apiClient := testAccProvider.Meta().(*client.Client)

for _, rs := range s.RootModule().Resources {
if rs.Type != "harbor_garbage_collection" {
continue
}

resp, _, err := apiClient.SendRequest("GET", rs.Primary.ID, nil, 200)
if err != nil {
return fmt.Errorf("Resouse was not delete \n %s", resp)
}
if resp != "" {
return fmt.Errorf("Resouse was not delete \n %s", resp)
}

}

return nil
}

func TestAccGCUpdate(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckGCDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckGCBasic(),
Check: resource.ComposeTestCheckFunc(
testAccCheckResourceExists(harborGCMain),
resource.TestCheckResourceAttr(
harborGCMain, "schedule", "daily"),
),
},
{
Config: testAccCheckGCUpdate(),
Check: resource.ComposeTestCheckFunc(
testAccCheckResourceExists(harborGCMain),
resource.TestCheckResourceAttr(
harborGCMain, "schedule", "hourly"),
resource.TestCheckResourceAttr(
harborGCMain, "delete_untagged", "true"),
),
},
},
})
}

func testAccCheckGCBasic() string {
return fmt.Sprintf(`
resource "harbor_garbage_collection" "main" {
schedule = "daily"
}
`)
}

func testAccCheckGCUpdate() string {
return fmt.Sprintf(`
resource "harbor_garbage_collection" "main" {
schedule = "hourly"
delete_untagged = true
}
`)
}
15 changes: 8 additions & 7 deletions provider/resource_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

const resourceHarborProjectMain = "harbor_project.main"
const enableContentTrust = "enable_content_trust"

func testAccCheckProjectDestroy(s *terraform.State) error {
apiClient := testAccProvider.Meta().(*client.Client)
Expand Down Expand Up @@ -47,7 +48,7 @@ func TestAccProjectBasic(t *testing.T) {
resource.TestCheckResourceAttr(
resourceHarborProjectMain, "vulnerability_scanning", "false"),
resource.TestCheckResourceAttr(
resourceHarborProjectMain, "enable_content_trust", "false"),
resourceHarborProjectMain, enableContentTrust, "false"),
),
},
},
Expand All @@ -71,7 +72,7 @@ func TestAccProjectUpdate(t *testing.T) {
resource.TestCheckResourceAttr(
resourceHarborProjectMain, "vulnerability_scanning", "false"),
resource.TestCheckResourceAttr(
resourceHarborProjectMain, "enable_content_trust", "false"),
resourceHarborProjectMain, enableContentTrust, "false"),
),
},
{
Expand All @@ -85,7 +86,7 @@ func TestAccProjectUpdate(t *testing.T) {
resource.TestCheckResourceAttr(
resourceHarborProjectMain, "vulnerability_scanning", "true"),
resource.TestCheckResourceAttr(
resourceHarborProjectMain, "enable_content_trust", "true"),
resourceHarborProjectMain, enableContentTrust, "true"),
),
},
},
Expand All @@ -98,9 +99,9 @@ func testAccCheckProjectBasic() string {
name = "test_basic"
public = false
vulnerability_scanning = false
enable_content_trust = false
%v = false
}
`)
`, enableContentTrust)
}

func testAccCheckItemUpdate() string {
Expand All @@ -109,7 +110,7 @@ func testAccCheckItemUpdate() string {
name = "test_basic"
public = true
vulnerability_scanning = true
enable_content_trust = true
%v = true
}
`)
`, enableContentTrust)
}

0 comments on commit 0901cdb

Please sign in to comment.