-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_test.go
More file actions
127 lines (108 loc) · 2.82 KB
/
github_test.go
File metadata and controls
127 lines (108 loc) · 2.82 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"testing"
)
const sampleURL = "https://github.com/hata/gorep"
func Test_newGithubAccess(t *testing.T) {
ga := newGithubAccess(sampleURL)
if ga.client == nil {
t.Error("Verify github.Client is initialized.")
}
if ga.url == "" {
t.Error("Verify github url is set")
}
}
func Test_parseURL(t *testing.T) {
ga := newGithubAccess(sampleURL)
err := ga.parseURL()
if err != nil {
t.Log(err)
t.Error("error should not be return.")
}
if ga.owner != "hata" {
t.Error("Verify owner should be set")
}
if ga.repos != "gorep" {
t.Error("Verify repos should be set")
}
if ga.basePath != "" {
t.Error("Verify path should be set")
}
}
func Test_parseURL_directory(t *testing.T) {
ga := newGithubAccess(sampleURL + "/tree/master/book")
err := ga.parseURL()
if err != nil {
t.Log(err)
t.Error("error should not be return.")
}
if ga.owner != "hata" {
t.Error("Verify owner should be set")
}
if ga.repos != "gorep" {
t.Error("Verify repos should be set")
}
if ga.basePath != "book" {
t.Error("Verify path should be set")
}
}
func Test_parseURL_wrong_url(t *testing.T) {
ga := newGithubAccess("http://www.google.com")
err := ga.parseURL()
if err == nil {
t.Error("Verify error should be return.")
}
}
func Test_getZipArchive(t *testing.T) {
ga := newGithubAccess(sampleURL)
zipReader, err := ga.getZipArchive()
if err != nil {
t.Error("There is an error to get archive" + err.Error())
}
if zipReader == nil {
t.Error("No zip body is returned.")
}
if len(zipReader.File) == 0 {
t.Error("No zip len is returned.")
}
}
func Test_getZipArchive_checkZipArchive(t *testing.T) {
ga := newGithubAccess(sampleURL)
_, err := ga.getZipArchive()
if err != nil {
t.Error("There is an error to getarchive 2 " + err.Error())
}
}
func Test_EachSource(t *testing.T) {
found := false
ga := newGithubAccess(sampleURL)
ga.EachSource(func (fs FileSource) error {
if fs.SubPath() == ".gitignore" {
found = true
}
return nil
})
if !found {
t.Error("Verify there is a file.")
}
}
func Test_EachSource_for_directory(t *testing.T) {
gitIgnoreFound := false
fileFound := false
ga := newGithubAccess(sampleURL + "/book")
ga.EachSource(func (fs FileSource) error {
if fs.SubPath() == ".gitignore" {
gitIgnoreFound = true
}
if fs.SubPath() == "chapter.go" {
fileFound = true
}
return nil
})
if gitIgnoreFound {
t.Error("Verify this should not be found")
}
if !fileFound {
t.Error("Verify a file found")
}
}