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

Function TestStringSet

db/string_test.go:142–214  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

140}
141
142func TestStringSet(t *testing.T) {
143 var exp = []int64{int64(2 * time.Second)}
144 type args struct {
145 val []byte
146 expire []int64
147 }
148 type want struct {
149 val []byte
150 err error
151 }
152 tests := []struct {
153 name string
154 key []byte
155 args args
156 want want
157 }{
158 {
159 name: "set no expire",
160 key: TestExistKey,
161 args: args{
162 val: value,
163 expire: nil,
164 },
165 want: want{
166 val: value,
167 err: nil,
168 },
169 },
170 {
171 name: "set expire",
172 key: TestExpireExistKey,
173 args: args{
174 val: value,
175 expire: exp,
176 },
177 want: want{
178 val: nil,
179 err: ErrKeyNotFound,
180 },
181 },
182 }
183 for _, tt := range tests {
184 t.Run(tt.name, func(t *testing.T) {
185 callFunc := func(txn *Transaction) {
186 s, err := GetString(txn, tt.key)
187 assert.NoError(t, err)
188 err = s.Set(tt.args.val, tt.args.expire...)
189 assert.NoError(t, err)
190 }
191 MockTest(t, callFunc)
192
193 if len(tt.args.expire) != 0 {
194 callFunc = func(txn *Transaction) {
195 s, err := GetString(txn, tt.key)
196 assert.NoError(t, err)
197 val, err := s.Get()
198 assert.NoError(t, err)
199 assert.Equal(t, tt.args.val, val)

Callers

nothing calls this directly

Calls 4

GetStringFunction · 0.85
MockTestFunction · 0.85
GetMethod · 0.80
SetMethod · 0.65

Tested by

no test coverage detected