Skip to content

Commit e1bc3a7

Browse files
committed
move examples to github_test package in examples_test.go
See #367 for discussion. Change-Id: I10e26bddebeea2a1485fc4389caab1ff12421382
1 parent 71e65bb commit e1bc3a7

File tree

5 files changed

+75
-60
lines changed

5 files changed

+75
-60
lines changed

github/examples_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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_test
7+
8+
import (
9+
"fmt"
10+
"log"
11+
12+
"github.com/google/go-github/github"
13+
)
14+
15+
func ExampleClient_Markdown() {
16+
client := github.NewClient(nil)
17+
18+
input := "# heading #\n\nLink to issue #1"
19+
opt := &github.MarkdownOptions{Mode: "gfm", Context: "google/go-github"}
20+
21+
output, _, err := client.Markdown(input, opt)
22+
if err != nil {
23+
fmt.Println(err)
24+
}
25+
26+
fmt.Println(output)
27+
}
28+
29+
func ExampleRepositoriesService_GetReadme() {
30+
client := github.NewClient(nil)
31+
32+
readme, _, err := client.Repositories.GetReadme("google", "go-github", nil)
33+
if err != nil {
34+
fmt.Println(err)
35+
return
36+
}
37+
38+
content, err := readme.GetContent()
39+
if err != nil {
40+
fmt.Println(err)
41+
return
42+
}
43+
44+
fmt.Printf("google/go-github README:\n%v\n", content)
45+
}
46+
47+
func ExampleRepositoriesService_List() {
48+
client := github.NewClient(nil)
49+
50+
user := "willnorris"
51+
opt := &github.RepositoryListOptions{Type: "owner", Sort: "updated", Direction: "desc"}
52+
53+
repos, _, err := client.Repositories.List(user, opt)
54+
if err != nil {
55+
fmt.Println(err)
56+
}
57+
58+
fmt.Printf("Recently updated repositories by %q: %v", user, github.Stringify(repos))
59+
}
60+
61+
func ExampleUsersService_ListAll() {
62+
client := github.NewClient(nil)
63+
opts := &github.UserListOptions{}
64+
for {
65+
users, _, err := client.Users.ListAll(opts)
66+
if err != nil {
67+
log.Fatalf("error listing users: %v", err)
68+
}
69+
if len(users) == 0 {
70+
break
71+
}
72+
opts.Since = *users[len(users)-1].ID
73+
// Process users...
74+
}
75+
}

github/misc_test.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,6 @@ func TestMarkdown(t *testing.T) {
4646
}
4747
}
4848

49-
func ExampleClient_Markdown() {
50-
client := NewClient(nil)
51-
52-
input := "# heading #\n\nLink to issue #1"
53-
opt := &MarkdownOptions{Mode: "gfm", Context: "google/go-github"}
54-
55-
output, _, err := client.Markdown(input, opt)
56-
if err != nil {
57-
fmt.Println(err)
58-
}
59-
60-
fmt.Println(output)
61-
}
62-
6349
func TestListEmojis(t *testing.T) {
6450
setup()
6551
defer teardown()

github/repos_contents_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,6 @@ func TestRepositoriesService_GetReadme(t *testing.T) {
119119
}
120120
}
121121

122-
func ExampleRepositoriesService_GetReadme() {
123-
client := NewClient(nil)
124-
125-
readme, _, err := client.Repositories.GetReadme("google", "go-github", nil)
126-
if err != nil {
127-
fmt.Println(err)
128-
return
129-
}
130-
131-
content, err := readme.GetContent()
132-
if err != nil {
133-
fmt.Println(err)
134-
return
135-
}
136-
137-
fmt.Printf("google/go-github README:\n%v\n", content)
138-
}
139-
140122
func TestRepositoriesService_DownloadContents_Success(t *testing.T) {
141123
setup()
142124
defer teardown()

github/repos_test.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,6 @@ func TestRepositoriesService_List_invalidUser(t *testing.T) {
6767
testURLParseError(t, err)
6868
}
6969

70-
func ExampleRepositoriesService_List() {
71-
client := NewClient(nil)
72-
73-
user := "willnorris"
74-
opt := &RepositoryListOptions{Type: "owner", Sort: "updated", Direction: "desc"}
75-
76-
repos, _, err := client.Repositories.List(user, opt)
77-
if err != nil {
78-
fmt.Println(err)
79-
}
80-
81-
fmt.Printf("Recently updated repositories by %q: %v", user, Stringify(repos))
82-
}
83-
8470
func TestRepositoriesService_ListByOrg(t *testing.T) {
8571
setup()
8672
defer teardown()

github/users.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,6 @@ type UserListOptions struct {
145145
// ListAll lists all GitHub users.
146146
//
147147
// To paginate through all users, populate 'Since' with the ID of the last user.
148-
// Example (warning: this will quickly eat through your GitHub API quota!):
149-
//
150-
// opts := &github.UserListOptions{}
151-
// for {
152-
// users, _, err := client.Users.ListAll(opts)
153-
// if err != nil {
154-
// log.Fatalf("error listing users: %v", err)
155-
// }
156-
// if len(users) == 0 {
157-
// break
158-
// }
159-
// opts.Since = *users[len(users)-1].ID
160-
// // Process users...
161-
// }
162148
//
163149
// GitHub API docs: http://developer.github.com/v3/users/#get-all-users
164150
func (s *UsersService) ListAll(opt *UserListOptions) ([]User, *Response, error) {

0 commit comments

Comments
 (0)