test set ex NX|XX|未知
(t *testing.T)
| 70 | |
| 71 | // test set ex NX|XX|未知 |
| 72 | func TestStringSetEXS(t *testing.T) { |
| 73 | |
| 74 | key := "setexs" |
| 75 | args := SetEXS(key) |
| 76 | |
| 77 | ctx := ContextTest("set", args...) |
| 78 | Call(ctx) |
| 79 | assert.Contains(t, ctxString(ctx.Out), "OK") |
| 80 | EqualGet(t, key, value, nil) |
| 81 | EqualStrlen(t, key, len(value)) |
| 82 | |
| 83 | //修改key失败 |
| 84 | args = SetEXS(key) |
| 85 | args[1] = "v2" |
| 86 | ctx = ContextTest("set", args...) |
| 87 | Call(ctx) |
| 88 | assert.Contains(t, ctxString(ctx.Out), "-1") |
| 89 | EqualGet(t, key, value, nil) |
| 90 | |
| 91 | args = SetEXS(key) |
| 92 | args[1] = "v2" |
| 93 | args[4] = "xx" |
| 94 | |
| 95 | ctx = ContextTest("set", args...) |
| 96 | Call(ctx) |
| 97 | assert.Contains(t, ctxString(ctx.Out), "OK") |
| 98 | EqualGet(t, key, "v2", nil) |
| 99 | EqualStrlen(t, key, len("v2")) |
| 100 | // 测试nx |
| 101 | // 修改key 失败 |
| 102 | args = SetEXS(key) |
| 103 | args[1] = "value" |
| 104 | ctx = ContextTest("set", args...) |
| 105 | Call(ctx) |
| 106 | assert.Contains(t, ctxString(ctx.Out), "-1") |
| 107 | EqualGet(t, key, "v2", nil) |
| 108 | |
| 109 | //乱序测试 |
| 110 | args[0] = key |
| 111 | args[1] = "v1" |
| 112 | args[2] = "xx" |
| 113 | args[3] = "ex" |
| 114 | args[4] = "1000" |
| 115 | |
| 116 | ctx = ContextTest("set", args...) |
| 117 | Call(ctx) |
| 118 | assert.Contains(t, ctxString(ctx.Out), "OK") |
| 119 | EqualGet(t, key, "v1", nil) |
| 120 | |
| 121 | //异常测试 |
| 122 | args = SetEXS(key) |
| 123 | ctx = ContextTest("set", args[:3]...) |
| 124 | Call(ctx) |
| 125 | assert.Contains(t, ctxString(ctx.Out), ErrSyntax.Error()) |
| 126 | |
| 127 | //异常测试 |
| 128 | args = SetEXS(key) |
| 129 | args[3] = "bx" |
nothing calls this directly
no test coverage detected