MCPcopy Create free account
hub / github.com/distributedio/titan / TestStringSetPXS

Function TestStringSetPXS

command/strings_test.go:136–200  ·  view source on GitHub ↗

test set px NX|XX|未知

(t *testing.T)

Source from the content-addressed store, hash-verified

134
135// test set px NX|XX|未知
136func TestStringSetPXS(t *testing.T) {
137
138 key := "setpx"
139 args := SetPXS(key)
140
141 ctx := ContextTest("set", args...)
142 Call(ctx)
143 assert.Contains(t, ctxString(ctx.Out), "OK")
144 EqualGet(t, key, value, nil)
145
146 //修改key失败
147 args = SetPXS(key)
148 args[1] = "v2"
149
150 ctx = ContextTest("set", args...)
151 Call(ctx)
152 assert.Contains(t, ctxString(ctx.Out), "-1")
153 EqualGet(t, key, value, nil)
154
155 // 测试nx
156 args = SetPXS(key)
157 args[1] = "v2"
158 args[4] = "xx"
159
160 ctx = ContextTest("set", args...)
161 Call(ctx)
162 assert.Contains(t, ctxString(ctx.Out), "OK")
163 EqualGet(t, key, args[1], nil)
164
165 // 修改key 失败
166 // key =
167 args = SetPXS("kpx2")
168 args[4] = "xx"
169
170 ctx = ContextTest("set", args...)
171 Call(ctx)
172 assert.Contains(t, ctxString(ctx.Out), "-1")
173 EqualGet(t, key, "v2", nil)
174
175 //异常测试
176 ctx = ContextTest("set", args[:3]...)
177 Call(ctx)
178 assert.Contains(t, ctxString(ctx.Out), ErrSyntax.Error())
179
180 //乱序测试
181 args[0] = key
182 args[1] = "v1"
183 args[2] = "xx"
184 args[3] = "px"
185 args[4] = "10000"
186
187 ctx = ContextTest("set", args[:3]...)
188 Call(ctx)
189 assert.Contains(t, ctxString(ctx.Out), "OK")
190 EqualGet(t, key, "v1", nil)
191
192 //异常测试
193 args = SetPXS(key)

Callers

nothing calls this directly

Calls 6

SetPXSFunction · 0.85
ContextTestFunction · 0.85
CallFunction · 0.85
ctxStringFunction · 0.85
EqualGetFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected