|
| 1 | +// Copyright 2016 The go-github AUTHORS. All rights reserved. |
| 2 | +// |
| 3 | +// Use of this source code is governed by a BSD-style |
| 4 | +// license that can be found in the LICENSE file. |
| 5 | + |
| 6 | +package github |
| 7 | + |
| 8 | +import ( |
| 9 | + "net/http" |
| 10 | + "reflect" |
| 11 | + "testing" |
| 12 | +) |
| 13 | + |
| 14 | +func TestActivityService_List(t *testing.T) { |
| 15 | + setup() |
| 16 | + defer teardown() |
| 17 | + |
| 18 | + mux.HandleFunc("/feeds", func(w http.ResponseWriter, r *http.Request) { |
| 19 | + testMethod(t, r, "GET") |
| 20 | + |
| 21 | + w.WriteHeader(http.StatusOK) |
| 22 | + w.Write(feedsJSON) |
| 23 | + }) |
| 24 | + |
| 25 | + got, _, err := client.Activity.ListFeeds() |
| 26 | + if err != nil { |
| 27 | + t.Errorf("Activity.ListFeeds returned error: %v", err) |
| 28 | + } |
| 29 | + if want := wantFeeds; !reflect.DeepEqual(got, want) { |
| 30 | + t.Errorf("Activity.ListFeeds = %+v, want %+v", got, want) |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +var feedsJSON = []byte(`{ |
| 35 | + "timeline_url": "https://github.com/timeline", |
| 36 | + "user_url": "https://github.com/{user}", |
| 37 | + "current_user_public_url": "https://github.com/defunkt", |
| 38 | + "current_user_url": "https://github.com/defunkt.private?token=abc123", |
| 39 | + "current_user_actor_url": "https://github.com/defunkt.private.actor?token=abc123", |
| 40 | + "current_user_organization_url": "", |
| 41 | + "current_user_organization_urls": [ |
| 42 | + "https://github.com/organizations/github/defunkt.private.atom?token=abc123" |
| 43 | + ], |
| 44 | + "_links": { |
| 45 | + "timeline": { |
| 46 | + "href": "https://github.com/timeline", |
| 47 | + "type": "application/atom+xml" |
| 48 | + }, |
| 49 | + "user": { |
| 50 | + "href": "https://github.com/{user}", |
| 51 | + "type": "application/atom+xml" |
| 52 | + }, |
| 53 | + "current_user_public": { |
| 54 | + "href": "https://github.com/defunkt", |
| 55 | + "type": "application/atom+xml" |
| 56 | + }, |
| 57 | + "current_user": { |
| 58 | + "href": "https://github.com/defunkt.private?token=abc123", |
| 59 | + "type": "application/atom+xml" |
| 60 | + }, |
| 61 | + "current_user_actor": { |
| 62 | + "href": "https://github.com/defunkt.private.actor?token=abc123", |
| 63 | + "type": "application/atom+xml" |
| 64 | + }, |
| 65 | + "current_user_organization": { |
| 66 | + "href": "", |
| 67 | + "type": "" |
| 68 | + }, |
| 69 | + "current_user_organizations": [ |
| 70 | + { |
| 71 | + "href": "https://github.com/organizations/github/defunkt.private.atom?token=abc123", |
| 72 | + "type": "application/atom+xml" |
| 73 | + } |
| 74 | + ] |
| 75 | + } |
| 76 | +}`) |
| 77 | + |
| 78 | +var wantFeeds = &Feeds{ |
| 79 | + TimelineURL: String("https://github.com/timeline"), |
| 80 | + UserURL: String("https://github.com/{user}"), |
| 81 | + CurrentUserPublicURL: String("https://github.com/defunkt"), |
| 82 | + CurrentUserURL: String("https://github.com/defunkt.private?token=abc123"), |
| 83 | + CurrentUserActorURL: String("https://github.com/defunkt.private.actor?token=abc123"), |
| 84 | + CurrentUserOrganizationURL: String(""), |
| 85 | + CurrentUserOrganizationURLs: []string{ |
| 86 | + "https://github.com/organizations/github/defunkt.private.atom?token=abc123", |
| 87 | + }, |
| 88 | + Links: &struct { |
| 89 | + Timeline *FeedLink `json:"timeline,omitempty"` |
| 90 | + User *FeedLink `json:"user,omitempty"` |
| 91 | + CurrentUserPublic *FeedLink `json:"current_user_public,omitempty"` |
| 92 | + CurrentUser *FeedLink `json:"current_user,omitempty"` |
| 93 | + CurrentUserActor *FeedLink `json:"current_user_actor,omitempty"` |
| 94 | + CurrentUserOrganization *FeedLink `json:"current_user_organization,omitempty"` |
| 95 | + CurrentUserOrganizations []FeedLink `json:"current_user_organizations,omitempty"` |
| 96 | + }{ |
| 97 | + Timeline: &FeedLink{ |
| 98 | + HRef: String("https://github.com/timeline"), |
| 99 | + Type: String("application/atom+xml"), |
| 100 | + }, |
| 101 | + User: &FeedLink{ |
| 102 | + HRef: String("https://github.com/{user}"), |
| 103 | + Type: String("application/atom+xml"), |
| 104 | + }, |
| 105 | + CurrentUserPublic: &FeedLink{ |
| 106 | + HRef: String("https://github.com/defunkt"), |
| 107 | + Type: String("application/atom+xml"), |
| 108 | + }, |
| 109 | + CurrentUser: &FeedLink{ |
| 110 | + HRef: String("https://github.com/defunkt.private?token=abc123"), |
| 111 | + Type: String("application/atom+xml"), |
| 112 | + }, |
| 113 | + CurrentUserActor: &FeedLink{ |
| 114 | + HRef: String("https://github.com/defunkt.private.actor?token=abc123"), |
| 115 | + Type: String("application/atom+xml"), |
| 116 | + }, |
| 117 | + CurrentUserOrganization: &FeedLink{ |
| 118 | + HRef: String(""), |
| 119 | + Type: String(""), |
| 120 | + }, |
| 121 | + CurrentUserOrganizations: []FeedLink{ |
| 122 | + { |
| 123 | + HRef: String("https://github.com/organizations/github/defunkt.private.atom?token=abc123"), |
| 124 | + Type: String("application/atom+xml"), |
| 125 | + }, |
| 126 | + }, |
| 127 | + }, |
| 128 | +} |
0 commit comments