github.com/crosbymichael/octokat@v0.0.0-20160826194511-076a32289ed5/issues_test.go (about) 1 package octokat 2 3 import ( 4 "github.com/bmizerany/assert" 5 "net/http" 6 "testing" 7 "time" 8 ) 9 10 func TestIssues(t *testing.T) { 11 setup() 12 defer tearDown() 13 14 mux.HandleFunc("/repos/octocat/Hello-World/issues", func(w http.ResponseWriter, r *http.Request) { 15 testMethod(t, r, "GET") 16 respondWith(w, loadFixture("issues.json")) 17 }) 18 19 repo := Repo{UserName: "octocat", Name: "Hello-World"} 20 issues, _ := client.Issues(repo, nil) 21 22 assert.Equal(t, 1, len(issues)) 23 24 issue := issues[0] 25 26 validateIssue(t, issue) 27 28 } 29 30 func TestIssue(t *testing.T) { 31 setup() 32 defer tearDown() 33 34 mux.HandleFunc("/repos/octocat/Hello-World/issues/1347", func(w http.ResponseWriter, r *http.Request) { 35 testMethod(t, r, "GET") 36 respondWith(w, loadFixture("issue.json")) 37 }) 38 39 repo := Repo{UserName: "octocat", Name: "Hello-World"} 40 issue, _ := client.Issue(repo, 1347, nil) 41 42 validateIssue(t, issue) 43 } 44 45 func validateIssue(t *testing.T, issue *Issue) { 46 47 assert.Equal(t, "https://api.github.com/repos/octocat/Hello-World/issues/1347", issue.URL) 48 assert.Equal(t, "https://github.com/octocat/Hello-World/issues/1347", issue.HTMLURL) 49 assert.Equal(t, 1347, issue.Number) 50 assert.Equal(t, "open", issue.State) 51 assert.Equal(t, "Found a bug", issue.Title) 52 assert.Equal(t, "I'm having a problem with this.", issue.Body) 53 54 assert.Equal(t, "octocat", issue.User.Login) 55 assert.Equal(t, 1, issue.User.ID) 56 assert.Equal(t, "https://github.com/images/error/octocat_happy.gif", issue.User.AvatarURL) 57 assert.Equal(t, "somehexcode", issue.User.GravatarID) 58 assert.Equal(t, "https://api.github.com/users/octocat", issue.User.URL) 59 60 assert.Equal(t, 1, len(issue.Labels)) 61 assert.Equal(t, "https://api.github.com/repos/octocat/Hello-World/labels/bug", issue.Labels[0].URL) 62 assert.Equal(t, "bug", issue.Labels[0].Name) 63 64 assert.Equal(t, "octocat", issue.Assignee.Login) 65 assert.Equal(t, 1, issue.Assignee.ID) 66 assert.Equal(t, "https://github.com/images/error/octocat_happy.gif", issue.Assignee.AvatarURL) 67 assert.Equal(t, "somehexcode", issue.Assignee.GravatarID) 68 assert.Equal(t, "https://api.github.com/users/octocat", issue.Assignee.URL) 69 70 assert.Equal(t, "https://api.github.com/repos/octocat/Hello-World/milestones/1", issue.Milestone.URL) 71 assert.Equal(t, 1, issue.Milestone.Number) 72 assert.Equal(t, "open", issue.Milestone.State) 73 assert.Equal(t, "v1.0", issue.Milestone.Title) 74 assert.Equal(t, "", issue.Milestone.Description) 75 76 assert.Equal(t, "octocat", issue.Milestone.Creator.Login) 77 assert.Equal(t, 1, issue.Milestone.Creator.ID) 78 assert.Equal(t, "https://github.com/images/error/octocat_happy.gif", issue.Milestone.Creator.AvatarURL) 79 assert.Equal(t, "somehexcode", issue.Milestone.Creator.GravatarID) 80 assert.Equal(t, "https://api.github.com/users/octocat", issue.Milestone.Creator.URL) 81 82 assert.Equal(t, 4, issue.Milestone.OpenIssues) 83 assert.Equal(t, 8, issue.Milestone.ClosedIssues) 84 assert.Equal(t, "2011-04-10 20:09:31 +0000 UTC", issue.Milestone.CreatedAt.String()) 85 assert.Equal(t, (*time.Time)(nil), issue.Milestone.DueOn) 86 87 assert.Equal(t, 0, issue.Comments) 88 assert.Equal(t, "https://github.com/octocat/Hello-World/pull/1347", issue.PullRequest.HTMLURL) 89 assert.Equal(t, "https://github.com/octocat/Hello-World/pull/1347.diff", issue.PullRequest.DiffURL) 90 assert.Equal(t, "https://github.com/octocat/Hello-World/pull/1347.patch", issue.PullRequest.PatchURL) 91 92 assert.Equal(t, (*time.Time)(nil), issue.ClosedAt) 93 assert.Equal(t, "2011-04-22 13:33:48 +0000 UTC", issue.CreatedAt.String()) 94 assert.Equal(t, "2011-04-22 13:33:48 +0000 UTC", issue.UpdatedAt.String()) 95 96 // phew! 97 }