forked from gruntwork-io/fetch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
62 lines (52 loc) · 1.74 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"os"
"testing"
)
// Expect to download 2 assets:
// - health-checker_linux_386
// - health-checker_linux_amd64
const SAMPLE_RELEASE_ASSET_REGEX = "health-checker_linux_[a-z0-9]+"
func TestDownloadReleaseAssets(t *testing.T) {
tmpDir := mkTempDir(t)
logger := GetProjectLogger()
testInst := GitHubInstance{
BaseUrl: "github.com",
ApiUrl: "api.github.com",
}
githubRepo, err := ParseUrlIntoGitHubRepo(SAMPLE_RELEASE_ASSET_GITHUB_REPO_URL, "", testInst)
if err != nil {
t.Fatalf("Failed to parse sample release asset GitHub URL into Fetch GitHubRepo struct: %s", err)
}
assetPaths, fetchErr := downloadReleaseAssets(logger, SAMPLE_RELEASE_ASSET_REGEX, tmpDir, githubRepo, SAMPLE_RELEASE_ASSET_VERSION, false)
if fetchErr != nil {
t.Fatalf("Failed to download release asset: %s", fetchErr)
}
if len(assetPaths) != 2 {
t.Fatalf("Expected to download 2 assets, not %d", len(assetPaths))
}
for _, assetPath := range assetPaths {
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()
testInst := GitHubInstance{
BaseUrl: "github.com",
ApiUrl: "api.github.com",
}
githubRepo, err := ParseUrlIntoGitHubRepo(SAMPLE_RELEASE_ASSET_GITHUB_REPO_URL, "", testInst)
if err != nil {
t.Fatalf("Failed to parse sample release asset GitHub URL into Fetch GitHubRepo struct: %s", err)
}
_, fetchErr := downloadReleaseAssets(logger, "*", tmpDir, githubRepo, SAMPLE_RELEASE_ASSET_VERSION, false)
if fetchErr == nil {
t.Fatalf("Expected error for invalid regex")
}
}