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()