Skip to content

Commit

Permalink
Add tests to verify direct asset name comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
tonerdo committed Jan 23, 2022
1 parent 13b4c22 commit 1f23bae
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1f23bae

Please sign in to comment.