-
-
Notifications
You must be signed in to change notification settings - Fork 981
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding resolving relative urls to Terragrunt Provider Cache (#3318)
* fix: resolve relative url * chore: code improvements
- Loading branch information
1 parent
8e8192a
commit bb1c138
Showing
6 changed files
with
104 additions
and
13 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
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,14 @@ | ||
package models | ||
|
||
import ( | ||
"net/url" | ||
"path" | ||
"strings" | ||
) | ||
|
||
func resolveRelativeReference(base *url.URL, link string) string { | ||
if link != "" && !strings.HasPrefix(link, base.Scheme) { | ||
link = base.ResolveReference(&url.URL{Path: path.Join(base.Path, link)}).String() | ||
} | ||
return link | ||
} |
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,61 @@ | ||
package models | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestResolveRelativeReferences(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := []struct { | ||
baseURL string | ||
body ResponseBody | ||
expectedResolved ResponseBody | ||
}{ | ||
{ | ||
"https://releases.hashicorp.com/terraform-provider-local/2.5.1", | ||
ResponseBody{ | ||
DownloadURL: "terraform-provider-local_2.5.1_darwin_amd64.zip", | ||
SHA256SumsURL: "terraform-provider-local_2.5.1_SHA256SUMS", | ||
SHA256SumsSignatureURL: "terraform-provider-local_2.5.1_SHA256SUMS.72D7468F.sig", | ||
}, | ||
ResponseBody{ | ||
DownloadURL: "https://releases.hashicorp.com/terraform-provider-local/2.5.1/terraform-provider-local_2.5.1_darwin_amd64.zip", | ||
SHA256SumsURL: "https://releases.hashicorp.com/terraform-provider-local/2.5.1/terraform-provider-local_2.5.1_SHA256SUMS", | ||
SHA256SumsSignatureURL: "https://releases.hashicorp.com/terraform-provider-local/2.5.1/terraform-provider-local_2.5.1_SHA256SUMS.72D7468F.sig", | ||
}, | ||
}, | ||
{ | ||
"https://somehost.com", | ||
ResponseBody{ | ||
DownloadURL: "https://releases.hashicorp.com/terraform-provider-local/2.5.1/terraform-provider-local_2.5.1_darwin_amd64.zip", | ||
SHA256SumsURL: "https://releases.hashicorp.com/terraform-provider-local/2.5.1/terraform-provider-local_2.5.1_SHA256SUMS", | ||
SHA256SumsSignatureURL: "https://releases.hashicorp.com/terraform-provider-local/2.5.1/terraform-provider-local_2.5.1_SHA256SUMS.72D7468F.sig", | ||
}, | ||
ResponseBody{ | ||
DownloadURL: "https://releases.hashicorp.com/terraform-provider-local/2.5.1/terraform-provider-local_2.5.1_darwin_amd64.zip", | ||
SHA256SumsURL: "https://releases.hashicorp.com/terraform-provider-local/2.5.1/terraform-provider-local_2.5.1_SHA256SUMS", | ||
SHA256SumsSignatureURL: "https://releases.hashicorp.com/terraform-provider-local/2.5.1/terraform-provider-local_2.5.1_SHA256SUMS.72D7468F.sig", | ||
}, | ||
}, | ||
} | ||
|
||
for i, testCase := range testCases { | ||
testCase := testCase | ||
|
||
t.Run(fmt.Sprintf("testCase-%d", i), func(t *testing.T) { | ||
t.Parallel() | ||
|
||
baseURL, err := url.Parse(testCase.baseURL) | ||
require.NoError(t, err) | ||
|
||
actualResolved := testCase.body.ResolveRelativeReferences(baseURL) | ||
assert.Equal(t, testCase.expectedResolved, *actualResolved) | ||
}) | ||
} | ||
} |