-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from BESTSELLER/harbor_2.2_updates
Harbor 2.2 updates
- Loading branch information
Showing
5 changed files
with
112 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters