These tests assert the argument lists built by the XTRIM/XADD trimming commands without dispatching them to a server, with particular focus on the LIMIT clause semantics: - limit == 0 omits the LIMIT clause (historical behavior); - limit > 0 emits "LIMIT <limit>"; - limit < 0 (XTrimLimitDisabled) em
(t *testing.T)
| 15 | // - exact ("=") trim commands never emit LIMIT. |
| 16 | |
| 17 | func TestXTrim_LimitArgs(t *testing.T) { |
| 18 | ctx := context.Background() |
| 19 | |
| 20 | tests := []struct { |
| 21 | name string |
| 22 | call func(c cmdable) Cmder |
| 23 | want []interface{} |
| 24 | }{ |
| 25 | { |
| 26 | name: "maxlen_approx_limit_omitted", |
| 27 | call: func(c cmdable) Cmder { return c.XTrimMaxLenApprox(ctx, "stream", 100, 0) }, |
| 28 | want: []interface{}{"xtrim", "stream", "maxlen", "~", int64(100)}, |
| 29 | }, |
| 30 | { |
| 31 | name: "maxlen_approx_positive_limit", |
| 32 | call: func(c cmdable) Cmder { return c.XTrimMaxLenApprox(ctx, "stream", 100, 1000) }, |
| 33 | want: []interface{}{"xtrim", "stream", "maxlen", "~", int64(100), "limit", int64(1000)}, |
| 34 | }, |
| 35 | { |
| 36 | name: "maxlen_approx_limit_disabled", |
| 37 | call: func(c cmdable) Cmder { return c.XTrimMaxLenApprox(ctx, "stream", 100, XTrimLimitDisabled) }, |
| 38 | want: []interface{}{"xtrim", "stream", "maxlen", "~", int64(100), "limit", int64(0)}, |
| 39 | }, |
| 40 | { |
| 41 | name: "minid_approx_limit_omitted", |
| 42 | call: func(c cmdable) Cmder { return c.XTrimMinIDApprox(ctx, "stream", "4-0", 0) }, |
| 43 | want: []interface{}{"xtrim", "stream", "minid", "~", "4-0"}, |
| 44 | }, |
| 45 | { |
| 46 | name: "minid_approx_positive_limit", |
| 47 | call: func(c cmdable) Cmder { return c.XTrimMinIDApprox(ctx, "stream", "4-0", 42) }, |
| 48 | want: []interface{}{"xtrim", "stream", "minid", "~", "4-0", "limit", int64(42)}, |
| 49 | }, |
| 50 | { |
| 51 | name: "minid_approx_limit_disabled", |
| 52 | call: func(c cmdable) Cmder { return c.XTrimMinIDApprox(ctx, "stream", "4-0", XTrimLimitDisabled) }, |
| 53 | want: []interface{}{"xtrim", "stream", "minid", "~", "4-0", "limit", int64(0)}, |
| 54 | }, |
| 55 | { |
| 56 | name: "maxlen_exact_never_emits_limit", |
| 57 | call: func(c cmdable) Cmder { return c.XTrimMaxLen(ctx, "stream", 100) }, |
| 58 | want: []interface{}{"xtrim", "stream", "maxlen", "=", int64(100)}, |
| 59 | }, |
| 60 | { |
| 61 | name: "minid_exact_never_emits_limit", |
| 62 | call: func(c cmdable) Cmder { return c.XTrimMinID(ctx, "stream", "4-0") }, |
| 63 | want: []interface{}{"xtrim", "stream", "minid", "=", "4-0"}, |
| 64 | }, |
| 65 | { |
| 66 | name: "maxlen_approx_mode_limit_omitted", |
| 67 | call: func(c cmdable) Cmder { return c.XTrimMaxLenApproxMode(ctx, "stream", 100, 0, "KEEPREF") }, |
| 68 | want: []interface{}{"xtrim", "stream", "maxlen", "~", int64(100), "KEEPREF"}, |
| 69 | }, |
| 70 | { |
| 71 | name: "maxlen_approx_mode_positive_limit", |
| 72 | call: func(c cmdable) Cmder { return c.XTrimMaxLenApproxMode(ctx, "stream", 100, 1000, "KEEPREF") }, |
| 73 | want: []interface{}{"xtrim", "stream", "maxlen", "~", int64(100), "limit", int64(1000), "KEEPREF"}, |
| 74 | }, |
nothing calls this directly
no test coverage detected