MCPcopy
hub / github.com/perkeep/perkeep / MakeTestData

Method MakeTestData

pkg/importer/twitter/testdata.go:46–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44}
45
46func (im *imp) MakeTestData() http.RoundTripper {
47 const (
48 fakeMaxId = int64(486450108201201664) // Most recent tweet.
49 nTweets = 300 // Arbitrary number of tweets generated.
50 )
51 fakeMinId := fakeMaxId - nTweets // Oldest tweet in our timeline.
52
53 timeLineURL := apiURL + userTimeLineAPIPath
54 timeLineCached := make(map[int64]string)
55 okHeader := `HTTP/1.1 200 OK
56Content-Type: application/json; charset=UTF-8
57
58`
59 timeLineResponse := okHeader + fakeTimeLine(fakeMaxId, fakeMinId, timeLineCached)
60
61 fakePic := fakePicture()
62 responses := map[string]func() *http.Response{
63 timeLineURL: httputil.StaticResponder(timeLineResponse),
64 fmt.Sprintf("%s?count=%d&user_id=fakeUserID", timeLineURL, tweetRequestLimit): httputil.StaticResponder(timeLineResponse),
65 "https://twitpic.com/show/large/bar": httputil.FileResponder(fakePic),
66 "https://i.imgur.com/foo.gif": httputil.FileResponder(fakePic),
67 }
68
69 // register all the user_timeline calls (max_id varies) that should occur,
70 responses[fmt.Sprintf("%s?count=%d&max_id=%d&user_id=fakeUserID", timeLineURL, tweetRequestLimit, fakeMaxId-nTweets+1)] = httputil.StaticResponder(okHeader + fakeTimeLine(fakeMaxId-nTweets+1, fakeMinId, timeLineCached))
71 if nTweets > tweetRequestLimit {
72 // that is, once every tweetRequestLimit-1, going down from fakeMaxId.
73 for i := fakeMaxId; i > fakeMinId; i -= tweetRequestLimit - 1 {
74 responses[fmt.Sprintf("%s?count=%d&max_id=%d&user_id=fakeUserID", timeLineURL, tweetRequestLimit, i)] = httputil.StaticResponder(okHeader + fakeTimeLine(i, fakeMinId, timeLineCached))
75 }
76 }
77
78 // register all the possible combinations of media twimg
79 for _, scheme := range []string{"http://", "https://"} {
80 for _, picsize := range []string{"thumb", "small", "medium", "large"} {
81 responses[fmt.Sprintf("%spbs.twimg.com/media/foo.jpg:%s", scheme, picsize)] = httputil.FileResponder(fakePic)
82 responses[fmt.Sprintf("%spbs.twimg.com/media/bar.png:%s", scheme, picsize)] = httputil.FileResponder(fakePic)
83 }
84 }
85
86 return httputil.NewFakeTransport(responses)
87}
88
89// fakeTimeLine returns a JSON user timeline of tweetRequestLimit tweets, starting
90// with maxId as the most recent tweet id. It stops before tweetRequestLimit if

Callers

nothing calls this directly

Calls 5

StaticResponderFunction · 0.92
FileResponderFunction · 0.92
NewFakeTransportFunction · 0.92
fakeTimeLineFunction · 0.85
fakePictureFunction · 0.70

Tested by

no test coverage detected