forked from gruntwork-io/fetch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_test.go
109 lines (88 loc) · 2.35 KB
/
fetch_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
)
func TestTagsList(t *testing.T) {
t.Parallel()
// fetch tags or release tags based on cmd-line flags
r := repo{
Url: "https://github.com/foo/bar",
Owner: "foo",
Name: "bar",
Token: "dummytoken",
Api: s.URL,
}
// happy path ... release assets
oRel := fetchOpts{}
oRel.relAssets = []string{"foo.tgz", "bar.tgz"}
oRel.verbose = true
if tags, err := oRel.tagsList(r); err != nil {
t.Fatalf("... expected a list of published release tags from foo/bar, got\n%s", err)
} else if !reflect.DeepEqual(tags, relTagsExpected) {
t.Fatalf("got: %#v\nexpected: %#v", tags, relTagsExpected)
}
// happy path ... tags
oTag := fetchOpts{}
oRel.verbose = true
if tags, err := oTag.tagsList(r); err != nil {
t.Fatalf("... expected a tag list from foo/bar, got\n%s", err)
} else if !reflect.DeepEqual(tags, apiTagsExpected) {
t.Fatalf("got: %#v\nexpected: %#v", tags, apiTagsExpected)
}
}
func TestDo(t *testing.T) {
t.Parallel()
r := repo{
Url: "https://github.com/foo/bar",
Owner: "foo",
Name: "bar",
Token: "dummytoken",
Api: s.URL,
}
testDoFromPaths(t, r)
testDoReleaseAssets(t, r)
}
func testDoFromPaths(t *testing.T, r repo) {
// default behaviour:
// will download whole repo from latest tag.
//
// * from-path of / if user specified neither from-path nor release-asset
// * latest tag used.
//
// NOTE cli prevents defaulting to latest tag as user is required to
// choose a tag or tag constraint or branch or commit.
tempDir, err := ioutil.TempDir("", "")
if err != nil {
t.Fatalf("Failed to create temp directory: %s", err)
}
defer os.RemoveAll(tempDir)
o := fetchOpts{}
o.destDir = tempDir
err = o.do(r)
if err != nil {
t.Fatalf("Test failed to download latest foo/bar tag's src.%s", err)
}
// ... check for file in decompressed /root folder
f := fmt.Sprintf("%s/symlink", tempDir)
if yes := fileExists(f); !yes {
t.Fatalf("expected file %s does not exist", f)
}
}
func testDoReleaseAssets(t *testing.T, r repo) {
tempDir, err := ioutil.TempDir("", "")
if err != nil {
t.Fatalf("Failed to create temp directory: %s", err)
}
defer os.RemoveAll(tempDir)
o := fetchOpts{}
o.destDir = tempDir
o.relAssets = []string{"packed.tgz"}
err = o.do(r)
if err != nil {
t.Fatalf("Test failed to download release (7.6.5).\n%s", err)
}
}