MCPcopy
hub / github.com/perkeep/perkeep / fakeCheckinsList

Function fakeCheckinsList

pkg/importer/swarm/testdata.go:152–211  ·  view source on GitHub ↗

fakeCheckinsList returns a JSON checkins list of checkinsRequestLimit checkin items, starting at offset. It stops before checkinsRequestLimit if maxCheckin is reached. It uses towns to populate the venues. The returned list is saved in cached.

(offset, maxCheckin int, towns map[int]*venueLocationItem, cached map[int]string)

Source from the content-addressed store, hash-verified

150// reached. It uses towns to populate the venues. The returned list is saved in
151// cached.
152func fakeCheckinsList(offset, maxCheckin int, towns map[int]*venueLocationItem, cached map[int]string) string {
153 if cl, ok := cached[offset]; ok {
154 return cl
155 }
156 max := offset + checkinsRequestLimit
157 if max > maxCheckin {
158 max = maxCheckin
159 }
160 var items []*checkinItem
161 tzCounter := 0
162 venueCounter := 0
163 for i := offset; i < max; i++ {
164 shout := fmt.Sprintf("fakeShout %d", i)
165 item := &checkinItem{
166 Id: blob.RefFromString(shout).DigestPrefix(10),
167 Shout: shout,
168 With: []*user{
169 {
170 Id: "123",
171 FirstName: "Kate",
172 LastName: "Pek",
173 Photo: photoItem{
174 Prefix: "https://irs3.4sqi.net/img/user/",
175 Suffix: "/13674-S2IUMHALCCJJUTQO.jpg",
176 },
177 },
178 },
179 CreatedAt: time.Now().Unix(),
180 TimeZoneOffset: tzCounter * 60,
181 Venue: fakeVenue(venueCounter, towns),
182 }
183 items = append(items, item)
184 tzCounter++
185 venueCounter++
186 if tzCounter == 24 {
187 tzCounter = 0
188 }
189 if venueCounter == 5 {
190 venueCounter = 0
191 }
192 }
193
194 response := struct {
195 Checkins struct {
196 Items []*checkinItem
197 }
198 }{
199 Checkins: struct {
200 Items []*checkinItem
201 }{
202 Items: items,
203 },
204 }
205 list, err := json.MarshalIndent(checkinsList{Response: response}, "", " ")
206 if err != nil {
207 log.Fatalf("%v", err)
208 }
209 cached[offset] = string(list)

Callers 1

MakeTestDataMethod · 0.85

Calls 4

RefFromStringFunction · 0.92
fakeVenueFunction · 0.85
DigestPrefixMethod · 0.80
FatalfMethod · 0.65

Tested by

no test coverage detected