diff --git a/github_test.go b/github_test.go index 06c43e9..dd825ff 100644 --- a/github_test.go +++ b/github_test.go @@ -25,7 +25,7 @@ func TestGetListOfReleasesFromGitHubRepo(t *testing.T) { testInst GitHubInstance }{ // Test on a public repo whose sole purpose is to be a test fixture for this tool - {"https://github.com/gruntwork-io/fetch-test-public", "v0.0.1", "v0.0.3", 3, "", testInst}, + {"https://github.com/gruntwork-io/fetch-test-public", "v0.0.1", "v0.0.4", 4, "", testInst}, // Private repo equivalent {"https://github.com/gruntwork-io/fetch-test-private", "v0.0.2", "v0.0.2", 1, os.Getenv("GITHUB_OAUTH_TOKEN"), testInst}, diff --git a/main.go b/main.go index f7f8b69..851cb96 100644 --- a/main.go +++ b/main.go @@ -455,6 +455,11 @@ func findAssetsInRelease(assetRegex string, release GitHubReleaseApiResponse) ([ if matched { assetRef := asset matches = append(matches, &assetRef) + } else if asset.Name == assetRegex { + // Sometimes the actual asset name contains regex symbols that could mess up matching. + // Perform a direct comparison as a last resort. + assetRef := asset + matches = append(matches, &assetRef) } } diff --git a/main_test.go b/main_test.go index 825e5ff..6650539 100644 --- a/main_test.go +++ b/main_test.go @@ -42,6 +42,41 @@ func TestDownloadReleaseAssets(t *testing.T) { } } +func TestDownloadReleaseAssetsWithRegexCharacters(t *testing.T) { + tmpDir := mkTempDir(t) + logger := GetProjectLogger() + testInst := GitHubInstance{ + BaseUrl: "github.com", + ApiUrl: "api.github.com", + } + + const githubRepoUrl = "https://github.com/gruntwork-io/fetch-test-public" + const releaseAsset = "hello+world.txt" + const assetVersion = "v0.0.4" + + githubRepo, err := ParseUrlIntoGitHubRepo(githubRepoUrl, "", testInst) + if err != nil { + t.Fatalf("Failed to parse sample release asset GitHub URL into Fetch GitHubRepo struct: %s", err) + } + + assetPaths, fetchErr := downloadReleaseAssets(logger, releaseAsset, tmpDir, githubRepo, assetVersion, false) + if fetchErr != nil { + t.Fatalf("Failed to download release asset: %s", fetchErr) + } + + if len(assetPaths) != 1 { + t.Fatalf("Expected to download 1 assets, not %d", len(assetPaths)) + } + + assetPath := assetPaths[0] + + if _, err := os.Stat(assetPath); os.IsNotExist(err) { + t.Fatalf("Downloaded file should exist at %s", assetPath) + } else { + fmt.Printf("Verified the downloaded asset exists at %s\n", assetPath) + } +} + func TestInvalidReleaseAssetsRegex(t *testing.T) { tmpDir := mkTempDir(t) logger := GetProjectLogger()