diff --git a/terratest/outputs.tf b/terratest/outputs.tf index 54068798..3684bba0 100644 --- a/terratest/outputs.tf +++ b/terratest/outputs.tf @@ -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 +} diff --git a/terratest/terraform_test.go b/terratest/terraform_test.go index feb7e3b4..5ba977ba 100644 --- a/terratest/terraform_test.go +++ b/terratest/terraform_test.go @@ -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, @@ -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:p@example.com/foo?q=1#bar") + assert.Equal(t, urlParse["normalized_nofrag"], "http://u:p@example.com/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:p@example.com:80/foo?q=1#bar") + assert.Equal(t, urlParse["username"], "u") + homedir := "" homedirPath := "" diff --git a/terratest/url.tf b/terratest/url.tf new file mode 100644 index 00000000..47b628ee --- /dev/null +++ b/terratest/url.tf @@ -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:p@example.com:80/foo?q=1#bar" +}