Skip to content

Commit

Permalink
CI-8165: fixing github conn
Browse files Browse the repository at this point in the history
  • Loading branch information
RajBaviskar committed May 26, 2023
1 parent ce04df3 commit 7ffcc97
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/service/platform/connector/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func ResourceConnectorGithub() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"execute_on_delegate": {
Description: "Execute on delegate or not.",
Type: schema.TypeBool,
Optional: true,
},
"api_authentication": {
Description: "Configuration for using the github api. API Access is required for using “Git Experience”, for creation of Git based triggers, Webhooks management and updating Git statuses.",
Type: schema.TypeList,
Expand Down Expand Up @@ -215,6 +220,10 @@ func buildConnectorGithub(d *schema.ResourceData) *nextgen.ConnectorInfo {
connector.Github.Url = attr.(string)
}

if attr, ok := d.GetOk("execute_on_delegate"); ok {
connector.Github.ExecuteOnDelegate = attr.(bool)
}

if attr, ok := d.GetOk("delegate_selectors"); ok {
connector.Github.DelegateSelectors = utils.InterfaceSliceToStringSlice(attr.(*schema.Set).List())
}
Expand Down Expand Up @@ -310,6 +319,7 @@ func readConnectorGithub(d *schema.ResourceData, connector *nextgen.ConnectorInf
d.Set("url", connector.Github.Url)
d.Set("connection_type", connector.Github.Type_.String())
d.Set("delegate_selectors", connector.Github.DelegateSelectors)
d.Set("execute_on_delegate", connector.Github.ExecuteOnDelegate)
d.Set("validation_repo", connector.Github.ValidationRepo)

if connector.Github.Authentication != nil {
Expand Down
92 changes: 92 additions & 0 deletions internal/service/platform/connector/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,58 @@ import (
"github.com/stretchr/testify/require"
)

func TestAccResourceConnectorGithub_HttpExecuteOnDelegateFalse(t *testing.T) {

id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5))
name := id
updatedName := fmt.Sprintf("%s_updated", name)
resourceName := "harness_platform_connector_github.test"

resource.UnitTest(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
"time": {},
},
CheckDestroy: testAccConnectorDestroy(resourceName),
Steps: []resource.TestStep{
{
Config: testAccResourceConnectorGithub_httpExecuteOnDelegateFalse(id, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", id),
resource.TestCheckResourceAttr(resourceName, "identifier", id),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "description", "test"),
resource.TestCheckResourceAttr(resourceName, "tags.#", "1"),
resource.TestCheckResourceAttr(resourceName, "url", "https://github.com/account"),
resource.TestCheckResourceAttr(resourceName, "connection_type", "Account"),
resource.TestCheckResourceAttr(resourceName, "validation_repo", "some_repo"),
resource.TestCheckResourceAttr(resourceName, "delegate_selectors.#", "1"),
resource.TestCheckResourceAttr(resourceName, "credentials.0.http.0.username", "admin"),
resource.TestCheckResourceAttr(resourceName, "execute_on_delegate", "false"),
),
},
{
Config: testAccResourceConnectorGithub_httpExecuteOnDelegateFalse(id, updatedName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", id),
resource.TestCheckResourceAttr(resourceName, "identifier", id),
resource.TestCheckResourceAttr(resourceName, "name", updatedName),
resource.TestCheckResourceAttr(resourceName, "description", "test"),
resource.TestCheckResourceAttr(resourceName, "tags.#", "1"),
resource.TestCheckResourceAttr(resourceName, "credentials.0.http.0.username", "admin"),
resource.TestCheckResourceAttr(resourceName, "execute_on_delegate", "false"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccResourceConnectorGithub_Http(t *testing.T) {

id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5))
Expand Down Expand Up @@ -286,6 +338,46 @@ func TestAccResourceProject_DeleteUnderlyingResource(t *testing.T) {
})
}

func testAccResourceConnectorGithub_httpExecuteOnDelegateFalse(id string, name string) string {
return fmt.Sprintf(`
resource "harness_platform_secret_text" "test" {
identifier = "%[1]s"
name = "%[2]s"
description = "test"
tags = ["foo:bar"]
secret_manager_identifier = "harnessSecretManager"
value_type = "Inline"
value = "secret"
}
resource "harness_platform_connector_github" "test" {
identifier = "%[1]s"
name = "%[2]s"
description = "test"
tags = ["foo:bar"]
url = "https://github.com/account"
connection_type = "Account"
validation_repo = "some_repo"
delegate_selectors = ["harness-delegate"]
execute_on_delegate = false
credentials {
http {
username = "admin"
token_ref = "account.${harness_platform_secret_text.test.id}"
}
}
depends_on = [time_sleep.wait_4_seconds]
}
resource "time_sleep" "wait_4_seconds" {
depends_on = [harness_platform_secret_text.test]
destroy_duration = "4s"
}
`, id, name)
}

func testAccResourceConnectorGithub_http(id string, name string) string {
return fmt.Sprintf(`
resource "harness_platform_secret_text" "test" {
Expand Down

0 comments on commit 7ffcc97

Please sign in to comment.