-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestStorage_DeleteWithVersion.go
57 lines (46 loc) · 1.84 KB
/
TestStorage_DeleteWithVersion.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package storage_test_helper
import (
"context"
"fmt"
if_expression "github.com/golang-infrastructure/go-if-expression"
"github.com/storage-lock/go-storage"
storage_lock "github.com/storage-lock/go-storage-lock"
"github.com/stretchr/testify/assert"
"testing"
)
func TestStorage_DeleteWithVersion(t *testing.T, s storage.Storage) {
assert.NotNilf(t, s, "Storage is nil")
ctx, cancelFunc := context.WithTimeout(context.Background(), DefaultContextTimeout)
defer cancelFunc()
err := s.Init(ctx)
assert.Nilf(t, err, "Storage %s init error: %s", s.GetName(), if_expression.ReturnByFunc(err != nil, func() string {
return err.Error()
}, func() string {
return ""
}))
TestEnsureLockNotExists(t, s)
// 先插入一条
lockInformation := BuildTestLockInformation(t)
ctx2, cancelFunc2 := context.WithTimeout(context.Background(), DefaultContextTimeout)
defer cancelFunc2()
err = s.CreateWithVersion(ctx2, TestLockId, TestLockVersion, lockInformation)
assert.Nil(t, err)
// 确认能够查询得到
ctx3, cancelFunc3 := context.WithTimeout(context.Background(), DefaultContextTimeout)
defer cancelFunc3()
lockInformationJsonString, err := s.Get(ctx3, TestLockId)
assert.Nil(t, err)
assert.NotEmpty(t, lockInformationJsonString)
// 再尝试将这一条删除
ctx4, cancelFunc4 := context.WithTimeout(context.Background(), DefaultContextTimeout)
defer cancelFunc4()
err = s.DeleteWithVersion(ctx4, TestLockId, TestLockVersion, lockInformation)
assert.Nil(t, err)
// 然后再查询,应该就查不到了
ctx5, cancelFunc5 := context.WithTimeout(context.Background(), DefaultContextTimeout)
defer cancelFunc5()
lockInformationJsonString, err = s.Get(ctx5, TestLockId)
assert.ErrorIs(t, err, storage_lock.ErrLockNotFound)
assert.Empty(t, lockInformationJsonString)
t.Log(fmt.Sprintf("Storage %s test DeleteWithVersion done", s.GetName()))
}