-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote_private_test.go
198 lines (188 loc) · 6.38 KB
/
remote_private_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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package gogh
import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
exgithub "github.com/google/go-github/v35/github"
"github.com/kyoh86/gogh/v2/internal/github"
"github.com/kyoh86/gogh/v2/internal/githubv4"
)
func TestParseSpec(t *testing.T) {
t.Run("valid http URL", func(t *testing.T) {
want := Spec{host: "github.com", owner: "kyoh86", name: "gogh"}
got, err := parseSpec(&github.Repository{
CloneURL: ptr("https://github.com/kyoh86/gogh"),
})
if err != nil {
t.Fatalf("unexpected error: %q", err)
}
if diff := cmp.Diff(want, got, cmp.AllowUnexported(want)); diff != "" {
t.Errorf("result mistmatch\n-want, +got:\n%s", diff)
}
})
t.Run("unsupported (ssh) URL", func(t *testing.T) {
_, err := parseSpec(&github.Repository{
CloneURL: ptr("[email protected]:kyoh86/gogh.git"),
})
if err == nil {
t.Fatal("expected error, but not")
}
})
}
func TestIngestRepository(t *testing.T) {
t.Run("valid repository", func(t *testing.T) {
tim, _ := time.Parse("2006-01-02", "2021-01-01")
want := Repository{
URL: "https://github.com/kyoh86/gogh",
Description: "valid description",
Homepage: "valid homepage",
Language: "valid language",
UpdatedAt: tim,
Archived: true,
Private: false,
IsTemplate: true,
Fork: false,
Spec: Spec{host: "github.com", owner: "kyoh86", name: "gogh"},
Parent: &Spec{host: "github.com", owner: "kyoh86-tryouts", name: "test"},
}
got, err := ingestRepository(&github.Repository{
Description: ptr("valid description"),
Homepage: ptr("valid homepage"),
UpdatedAt: &exgithub.Timestamp{Time: tim},
CloneURL: ptr("https://github.com/kyoh86/gogh"),
Language: ptr("valid language"),
Fork: ptr(false),
Parent: &github.Repository{
CloneURL: ptr("https://github.com/kyoh86-tryouts/test"),
},
Archived: ptr(true),
Private: ptr(false),
IsTemplate: ptr(true),
})
if err != nil {
t.Fatalf("unexpected error: %q", err)
}
if diff := cmp.Diff(want, got, cmp.AllowUnexported(want), cmp.AllowUnexported(want.Spec)); diff != "" {
t.Errorf("result mistmatch\n-want, +got:\n%s", diff)
}
})
t.Run("unsupported (ssh) URL", func(t *testing.T) {
tim, _ := time.Parse("2006-01-02", "2021-01-01")
_, err := ingestRepository(&github.Repository{
Description: ptr("valid description"),
Homepage: ptr("valid homepage"),
UpdatedAt: &exgithub.Timestamp{Time: tim},
CloneURL: ptr("[email protected]:kyoh86/gogh.git"),
Language: ptr("valid language"),
Fork: ptr(false),
Parent: &github.Repository{
CloneURL: ptr("https://github.com/kyoh86-tryouts/test"),
},
Archived: ptr(true),
Private: ptr(false),
IsTemplate: ptr(true),
})
if err == nil {
t.Fatal("expected error, but not")
}
})
t.Run("unsupported (ssh) parent URL", func(t *testing.T) {
tim, _ := time.Parse("2006-01-02", "2021-01-01")
_, err := ingestRepository(&github.Repository{
Description: ptr("valid description"),
Homepage: ptr("valid homepage"),
UpdatedAt: &exgithub.Timestamp{Time: tim},
CloneURL: ptr("https://github.com/kyoh86/gogh"),
Language: ptr("valid language"),
Fork: ptr(false),
Parent: &github.Repository{
CloneURL: ptr("[email protected]:kyoh86-tryouts/test"),
},
Archived: ptr(true),
Private: ptr(false),
IsTemplate: ptr(true),
})
if err == nil {
t.Fatal("expected error, but not")
}
})
}
func TestIngestRepositoryFragment(t *testing.T) {
tim, _ := time.Parse("2006-01-02", "2021-01-01")
t.Run("valid repository", func(t *testing.T) {
want := Repository{
URL: "https://github.com/kyoh86/gogh",
Description: "valid description",
Homepage: "https://example.com",
Language: "valid language",
UpdatedAt: tim,
Archived: true,
Private: false,
IsTemplate: true,
Fork: false,
Spec: Spec{host: "github.com", owner: "kyoh86", name: "gogh"},
Parent: &Spec{host: "github.com", owner: "kyoh86-tryouts", name: "test"},
}
got, err := ingestRepositoryFragment("github.com", &github.RepositoryFragment{
Owner: &githubv4.RepositoryFragmentOwnerUser{OwnerFragmentUser: githubv4.OwnerFragmentUser{Login: "kyoh86"}},
Name: "gogh",
Description: "valid description",
HomepageUrl: "https://example.com",
UpdatedAt: tim,
Url: "https://github.com/kyoh86/gogh",
PrimaryLanguage: githubv4.RepositoryFragmentPrimaryLanguage{LanguageFragment: githubv4.LanguageFragment{Name: "valid language"}},
IsFork: false,
Parent: githubv4.RepositoryFragmentParentRepository{
ParentRepositoryFragment: githubv4.ParentRepositoryFragment{
Owner: &githubv4.ParentRepositoryFragmentOwnerOrganization{OwnerFragmentOrganization: githubv4.OwnerFragmentOrganization{Login: "kyoh86-tryouts"}},
Name: "test",
},
},
IsArchived: true,
IsPrivate: false,
IsTemplate: true,
})
if err != nil {
t.Fatalf("unexpected error: %q", err)
}
if diff := cmp.Diff(want, got, cmp.AllowUnexported(want), cmp.AllowUnexported(want.Spec)); diff != "" {
t.Errorf("result mistmatch\n-want, +got:\n%s", diff)
}
})
t.Run("invalid owner", func(t *testing.T) {
_, err := ingestRepositoryFragment("github.com", &github.RepositoryFragment{
Owner: &githubv4.RepositoryFragmentOwnerUser{OwnerFragmentUser: githubv4.OwnerFragmentUser{Login: ".."}},
Name: "gogh",
Url: "https://github.com/kyoh86/gogh",
UpdatedAt: tim,
IsFork: false,
IsArchived: true,
IsPrivate: false,
IsTemplate: true,
})
if err == nil {
t.Fatal("expected error, but not")
}
})
t.Run("invalid parent", func(t *testing.T) {
_, err := ingestRepositoryFragment("github.com", &github.RepositoryFragment{
Owner: &githubv4.RepositoryFragmentOwnerUser{OwnerFragmentUser: githubv4.OwnerFragmentUser{Login: "kyoh86"}},
Name: "gogh",
Url: "https://github.com/kyoh86/gogh",
UpdatedAt: tim,
Parent: githubv4.RepositoryFragmentParentRepository{
ParentRepositoryFragment: githubv4.ParentRepositoryFragment{
Owner: &githubv4.ParentRepositoryFragmentOwnerOrganization{OwnerFragmentOrganization: githubv4.OwnerFragmentOrganization{Login: ".."}},
Name: "..",
},
},
IsFork: false,
IsArchived: true,
IsPrivate: false,
IsTemplate: true,
})
if err == nil {
t.Fatal("expected error, but not")
}
})
}