Skip to content

Commit

Permalink
test: Added Terratest tests for corefunc_url_parse.
Browse files Browse the repository at this point in the history
  • Loading branch information
skyzyx committed Feb 5, 2024
1 parent 4efff9d commit d6f3437
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
8 changes: 8 additions & 0 deletions terratest/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,11 @@ output "runtime_os" {
description = "This returns the operating system of the provider."
value = data.corefunc_runtime_os.os.value
}

# ------------------------------------------------------------------------------
# URL Parsing

output "url_parse" {
description = "This returns a parsed URL."
value = data.corefunc_url_parse.url
}
38 changes: 27 additions & 11 deletions terratest/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,11 @@ func TestTerraform(t *testing.T) {
assert.Equal(t, terraform.Output(t, terraformOptions, "int_leftpad"), corefunc.IntLeftPad(123, 5))
assert.Equal(t, terraform.Output(t, terraformOptions, "str_leftpad"), corefunc.StrLeftPad("abc", 5, '.'))
assert.Equal(t, terraform.Output(t, terraformOptions, "env_ensure"), os.Getenv("GOROOT"))

assert.Equal(t, terraform.Output(t, terraformOptions, "runtime_cpuarch"), runtime.GOARCH)
assert.Equal(t, terraform.Output(t, terraformOptions, "runtime_goroot"), runtime.GOROOT())
assert.Equal(t, terraform.Output(t, terraformOptions, "runtime_numcpus"), fmt.Sprint(runtime.NumCPU()))
assert.Equal(t, terraform.Output(t, terraformOptions, "runtime_os"), runtime.GOOS)

assert.Equal(
t,
assert.Equal(t,
terraform.Output(t, terraformOptions, "str_truncate"),
corefunc.TruncateLabel(64, prefix, label),
)

assert.Equal(
t,
assert.Equal(t,
terraform.Output(t, terraformOptions, "str_iterative_replace"),
corefunc.StrIterativeReplace(
strToReplace,
Expand All @@ -130,6 +121,31 @@ func TestTerraform(t *testing.T) {
),
)

// runtime
assert.Equal(t, terraform.Output(t, terraformOptions, "runtime_cpuarch"), runtime.GOARCH)
assert.Equal(t, terraform.Output(t, terraformOptions, "runtime_goroot"), runtime.GOROOT())
assert.Equal(t, terraform.Output(t, terraformOptions, "runtime_numcpus"), fmt.Sprint(runtime.NumCPU()))
assert.Equal(t, terraform.Output(t, terraformOptions, "runtime_os"), runtime.GOOS)

// url_parse
urlParse := terraform.OutputMap(t, terraformOptions, "url_parse")
assert.Equal(t, urlParse["decoded_port"], fmt.Sprint(80))
assert.Equal(t, urlParse["fragment"], "bar")
assert.Equal(t, urlParse["hash"], "#bar")
assert.Equal(t, urlParse["host"], "example.com")
assert.Equal(t, urlParse["hostname"], "example.com")
assert.Equal(t, urlParse["normalized"], "http://u:[email protected]/foo?q=1#bar")
assert.Equal(t, urlParse["normalized_nofrag"], "http://u:[email protected]/foo?q=1")
assert.Equal(t, urlParse["password"], "p")
assert.Equal(t, urlParse["path"], "/foo")
assert.Equal(t, urlParse["port"], "")
assert.Equal(t, urlParse["protocol"], "http:")
assert.Equal(t, urlParse["query"], "q=1")
assert.Equal(t, urlParse["scheme"], "http")
assert.Equal(t, urlParse["search"], "?q=1")
assert.Equal(t, urlParse["url"], "HTTP://u:[email protected]:80/foo?q=1#bar")
assert.Equal(t, urlParse["username"], "u")

homedir := ""
homedirPath := ""

Expand Down
4 changes: 4 additions & 0 deletions terratest/url.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# https://registry.terraform.io/providers/northwood-labs/corefunc/latest/docs/data-sources/url_parse
data "corefunc_url_parse" "url" {
url = "HTTP://u:[email protected]:80/foo?q=1#bar"
}

0 comments on commit d6f3437

Please sign in to comment.