Fix to set MaxID and SinceID to exclusive

This commit is contained in:
178inaba 2017-05-08 13:44:49 +09:00
parent 9e07d8951e
commit 4033436175
3 changed files with 18 additions and 7 deletions

View File

@ -28,7 +28,6 @@ func cmdFollowers(c *cli.Context) error {
if pg.MaxID == 0 { if pg.MaxID == 0 {
break break
} }
pg.SinceID = 0
time.Sleep(10 * time.Second) time.Sleep(10 * time.Second)
} }
s := newScreen(config) s := newScreen(config)

View File

@ -263,13 +263,12 @@ func (p *Pagination) toValues() url.Values {
} }
func (p *Pagination) setValues(params url.Values) url.Values { func (p *Pagination) setValues(params url.Values) url.Values {
if p.MaxID != 0 { if p.MaxID > 0 {
params.Set("max_id", fmt.Sprint(p.MaxID)) params.Set("max_id", fmt.Sprint(p.MaxID))
} } else if p.SinceID > 0 {
if p.SinceID != 0 {
params.Set("since_id", fmt.Sprint(p.SinceID)) params.Set("since_id", fmt.Sprint(p.SinceID))
} }
if p.Limit != 0 { if p.Limit > 0 {
params.Set("limit", fmt.Sprint(p.Limit)) params.Set("limit", fmt.Sprint(p.Limit))
} }

View File

@ -339,10 +339,23 @@ func TestPaginationSetValues(t *testing.T) {
if after.Get("max_id") != "123" { if after.Get("max_id") != "123" {
t.Fatalf("want %q but %q", "123", after.Get("max_id")) t.Fatalf("want %q but %q", "123", after.Get("max_id"))
} }
if after.Get("since_id") != "789" { if after.Get("since_id") != "" {
t.Fatalf("want %q but %q", "789", after.Get("since_id")) t.Fatalf("result should be empty string: %q", after.Get("since_id"))
} }
if after.Get("limit") != "10" { if after.Get("limit") != "10" {
t.Fatalf("want %q but %q", "10", after.Get("limit")) t.Fatalf("want %q but %q", "10", after.Get("limit"))
} }
p = &Pagination{
MaxID: 0,
SinceID: 789,
}
before = url.Values{}
after = p.setValues(before)
if after.Get("max_id") != "" {
t.Fatalf("result should be empty string: %q", after.Get("max_id"))
}
if after.Get("since_id") != "789" {
t.Fatalf("want %q but %q", "789", after.Get("since_id"))
}
} }