Skip to content

Commit

Permalink
fix: support repository autolink references with non-standard ports
Browse files Browse the repository at this point in the history
  • Loading branch information
isometry committed Feb 16, 2023
1 parent 9cf65a4 commit 1fa61cd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 14 deletions.
2 changes: 1 addition & 1 deletion github/resource_github_repository_autolink_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func resourceGithubRepositoryAutolinkReference() *schema.Resource {
Required: true,
ForceNew: true,
Description: "The template of the target URL used for the links; must be a valid URL and contain `<num>` for the reference number",
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^http[s]?:\/\/[a-z0-9-.]*\/.*?<num>.*?$`), "must be a valid URL and contain <num> token"),
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^http[s]?:\/\/[a-z0-9-.]*(:[0-9]+)?\/.*?<num>.*?$`), "must be a valid URL and contain <num> token"),
},
"is_alphanumeric": {
Type: schema.TypeBool,
Expand Down
67 changes: 54 additions & 13 deletions github/resource_github_repository_autolink_reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,39 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) {

config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "test-%s"
description = "Test autolink creation"
name = "test-%s"
description = "Test autolink creation"
}
resource "github_repository_autolink_reference" "autolink_default" {
repository = github_repository.test.name
key_prefix = "TEST1-"
key_prefix = "TEST1-"
target_url_template = "https://example.com/TEST-<num>"
}
resource "github_repository_autolink_reference" "autolink_alphanumeric" {
repository = github_repository.test.name
key_prefix = "TEST2-"
key_prefix = "TEST2-"
target_url_template = "https://example.com/TEST-<num>"
is_alphanumeric = true
}
resource "github_repository_autolink_reference" "autolink_numeric" {
repository = github_repository.test.name
key_prefix = "TEST3-"
key_prefix = "TEST3-"
target_url_template = "https://example.com/TEST-<num>"
is_alphanumeric = false
}
resource "github_repository_autolink_reference" "autolink_with_port" {
repository = github_repository.test.name
key_prefix = "TEST4-"
target_url_template = "https://example.com:8443/TEST-<num>"
}
`, randomID)

check := resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -75,6 +82,16 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) {
resource.TestCheckResourceAttr(
"github_repository_autolink_reference.autolink_numeric", "is_alphanumeric", "false",
),
// autolink_with_port
resource.TestCheckResourceAttr(
"github_repository_autolink_reference.autolink_with_port", "key_prefix", "TEST4-",
),
resource.TestCheckResourceAttr(
"github_repository_autolink_reference.autolink_with_port", "target_url_template", "https://example.com:8443/TEST-<num>",
),
resource.TestCheckResourceAttr(
"github_repository_autolink_reference.autolink_with_port", "is_alphanumeric", "true",
),
)

testCase := func(t *testing.T, mode string) {
Expand Down Expand Up @@ -108,32 +125,39 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) {

config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "test-%s"
description = "Test autolink creation"
name = "test-%s"
description = "Test autolink creation"
}
resource "github_repository_autolink_reference" "autolink_default" {
repository = github_repository.test.name
key_prefix = "TEST1-"
key_prefix = "TEST1-"
target_url_template = "https://example.com/TEST-<num>"
}
resource "github_repository_autolink_reference" "autolink_alphanumeric" {
repository = github_repository.test.name
key_prefix = "TEST2-"
key_prefix = "TEST2-"
target_url_template = "https://example.com/TEST-<num>"
is_alphanumeric = true
}
resource "github_repository_autolink_reference" "autolink_numeric" {
repository = github_repository.test.name
key_prefix = "TEST3-"
key_prefix = "TEST3-"
target_url_template = "https://example.com/TEST-<num>"
is_alphanumeric = false
}
resource "github_repository_autolink_reference" "autolink_with_port" {
repository = github_repository.test.name
key_prefix = "TEST4-"
target_url_template = "https://example.com:8443/TEST-<num>"
}
`, randomID)

check := resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -167,6 +191,16 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) {
resource.TestCheckResourceAttr(
"github_repository_autolink_reference.autolink_numeric", "is_alphanumeric", "false",
),
// autolink_with_port
resource.TestCheckResourceAttr(
"github_repository_autolink_reference.autolink_with_port", "key_prefix", "TEST4-",
),
resource.TestCheckResourceAttr(
"github_repository_autolink_reference.autolink_with_port", "target_url_template", "https://example.com:8443/TEST-<num>",
),
resource.TestCheckResourceAttr(
"github_repository_autolink_reference.autolink_with_port", "is_alphanumeric", "true",
),
)

testCase := func(t *testing.T, mode string) {
Expand Down Expand Up @@ -199,6 +233,13 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) {
ImportStateVerify: true,
ImportStateIdPrefix: fmt.Sprintf("test-%s/", randomID),
},
// autolink_with_port
{
ResourceName: "github_repository_autolink_reference.autolink_with_port",
ImportState: true,
ImportStateVerify: true,
ImportStateIdPrefix: fmt.Sprintf("test-%s/", randomID),
},
},
})
}
Expand All @@ -221,14 +262,14 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) {

config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "test-%s"
description = "Test autolink creation"
name = "test-%s"
description = "Test autolink creation"
}
resource "github_repository_autolink_reference" "autolink_default" {
repository = github_repository.test.name
key_prefix = "TEST1-"
key_prefix = "TEST1-"
target_url_template = "https://example.com/TEST-<num>"
}
`, randomID)
Expand Down

0 comments on commit 1fa61cd

Please sign in to comment.