Skip to content

Commit ef0a543

Browse files
committed
Add unit test back in with note about gock thread safety
1 parent c69b681 commit ef0a543

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

cmd/gh-classroom/shared/shared_test.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,109 @@ func TestListAcceptedAssignments(t *testing.T) {
9494
assert.Equal(t, "student2", actual.AcceptedAssignments[0].Students[0].Login)
9595

9696
}
97+
98+
func TestListAllAcceptedAssignments(t *testing.T) {
99+
//This test should be OK however be aware that gock is not fully thread safe
100+
//https://github.com/h2non/gock#race-conditions
101+
//So if this test has intermittent failures this is the first place to look :)
102+
t.Setenv("GITHUB_TOKEN", "999")
103+
defer gock.Off()
104+
105+
gock.New("https://api.github.com").
106+
Get("/assignments/1").
107+
Reply(200).
108+
JSON(`{"id": 1,
109+
"title": "Assignment 1",
110+
"description": "This is the first assignment",
111+
"due_date": "2018-01-01",
112+
"accepted": 2,
113+
"classroom": {
114+
"id": 1,
115+
"name": "Classroom Name"
116+
},
117+
"starter_code_repository": {
118+
"id": 1,
119+
"full_name": "org1/starter-code-repo"
120+
}
121+
}`)
122+
123+
gock.New("https://api.github.com").
124+
Get("/assignments/1/accepted_assignments").
125+
Reply(200).
126+
JSON(`[{"id": 1,
127+
"assignment": {
128+
"id": 1,
129+
"title": "Assignment 1",
130+
"description": "This is the first assignment",
131+
"due_date": "2018-01-01",
132+
"classroom": {
133+
"id": 1,
134+
"name": "Classroom Name"
135+
},
136+
"starter_code_repository": {
137+
"id": 1,
138+
"full_name": "org1/starter-code-repo"
139+
}
140+
},
141+
"students": [{
142+
"id": 1,
143+
"login": "student1"
144+
}],
145+
"repository": {
146+
"id": 1,
147+
"full_name": "org1/student1-repo"
148+
}
149+
}]`)
150+
151+
gock.New("https://api.github.com").
152+
Path("/assignments/1/accepted_assignments").
153+
Reply(200).
154+
JSON(`[{"id": 2,
155+
"assignment": {
156+
"id": 2,
157+
"title": "Assignment 1",
158+
"description": "This is the first assignment",
159+
"due_date": "2018-01-01",
160+
"classroom": {
161+
"id": 1,
162+
"name": "Classroom Name"
163+
},
164+
"starter_code_repository": {
165+
"id": 1,
166+
"full_name": "org1/starter-code-repo"
167+
}
168+
},
169+
"students": [{
170+
"id": 2,
171+
"login": "student2"
172+
}],
173+
"repository": {
174+
"id": 2,
175+
"full_name": "org1/student2-repo"
176+
}
177+
}]`)
178+
179+
gock.New("https://api.github.com").
180+
Get("/assignments/1/accepted_assignments").
181+
Reply(200).
182+
JSON(`[]`)
183+
184+
client, err := gh.RESTClient(nil)
185+
if err != nil {
186+
t.Fatal(err)
187+
}
188+
189+
actual, err := ListAllAcceptedAssignments(client, 1, 1)
190+
191+
if err != nil {
192+
t.Fatal(err)
193+
}
194+
195+
assert.Equal(t, 2, actual.Count)
196+
assert.Equal(t, 1, actual.AcceptedAssignments[0].Id)
197+
assert.Equal(t, "org1/student1-repo", actual.AcceptedAssignments[0].Repository.FullName)
198+
assert.Equal(t, "student1", actual.AcceptedAssignments[0].Students[0].Login)
199+
assert.Equal(t, 2, actual.AcceptedAssignments[1].Id)
200+
assert.Equal(t, "org1/student2-repo", actual.AcceptedAssignments[1].Repository.FullName)
201+
assert.Equal(t, "student2", actual.AcceptedAssignments[1].Students[0].Login)
202+
}

0 commit comments

Comments
 (0)