Skip to content

Commit 3d2f2d2

Browse files
committed
Added Tests for GetUserData func in pkg githubapi
1 parent d150d50 commit 3d2f2d2

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

githubapi/githubapi_test.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,22 @@ func TestResponseToUserData(t *testing.T) {
4949
}
5050
}
5151

52-
func TestResponseToRepoData(t *testing.T) {
52+
func TestGetUserData(t *testing.T) {
53+
54+
var nil string
55+
56+
want := Userinfo{"Ocktokit", "https://github.com/Ocktokit", nil, nil, nil, 0, 0, 0}
57+
58+
var username string = "ocktokit"
59+
data := GetUserData(username)
60+
61+
if !reflect.DeepEqual(data, want) {
62+
t.Fatal("JSON Unmarshal failed.")
63+
}
64+
}
65+
66+
func TestResponseToRepoData(t *testing.T) { // Test needs fixing.
67+
5368
data := []byte(`[
5469
{
5570
"name": "GitHub_REST_API_consumer",
@@ -71,15 +86,14 @@ func TestResponseToRepoData(t *testing.T) {
7186
jsonResponse := responseToRepoData(data)
7287

7388
want := ReposInfoArray{
74-
75-
[]ReposInfoJson{
89+
[
7690
{"GitHub_REST_API_consumer", "https://github.com/iamargus95/GitHub_REST_API_consumer", 0},
7791
{"go-grep", "https://github.com/iamargus95/go-grep", 0},
78-
{"iamargus95", "https://github.com/iamargus95/iamargus95", 0},
79-
}
80-
} //Fix this test
92+
{"iamargus95", "https://github.com/iamargus95/iamargus95", 0}
93+
]
94+
}
8195

8296
if !reflect.DeepEqual(jsonResponse, want) {
8397
t.Fatal("JSON Unmarshal failed.")
8498
}
85-
}
99+
} // Test needs fixing.

main.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,14 @@ import (
88
)
99

1010
func main() {
11+
1112
fmt.Println("\n Enter desired GitHub username : \n ")
1213
username := getUsername()
13-
1414
userDetails := githubapi.GetUserData(username)
15-
1615
reposDetails := githubapi.GetReposData(username, userDetails.Public_repos)
17-
1816
userdata := githubapi.UserData(userDetails)
19-
2017
repodata := githubapi.RepoData(reposDetails)
21-
2218
io.WriteToFile(username, strings.Split(userdata, ","))
23-
2419
io.WriteToFile(username, repodata)
2520
}
2621

0 commit comments

Comments
 (0)