Skip to content

Commit bf2d147

Browse files
committed
add etcd lock tests
1 parent f7eaf39 commit bf2d147

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ cloc:
3838
cloc --exclude-dir=vendor,3rdmocks,mocks --not-match-f=test .
3939

4040
unit-test:
41-
go test --race -cover ./utils/... ./types/... ./store/etcdv3/... ./scheduler/complex/... ./source/common/... ./network/sdn/...
41+
go test --race -cover ./utils/... ./types/... ./store/etcdv3/... ./scheduler/complex/... ./source/common/... ./network/sdn/... ./lock/etcdlock/...

lock/etcdlock/lock_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package etcdlock
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
9+
"github.com/coreos/etcd/integration"
10+
)
11+
12+
func TestLock(t *testing.T) {
13+
cluster := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
14+
defer cluster.Terminate(t)
15+
cli := cluster.RandClient()
16+
17+
_, err := New(cli, "", 1)
18+
assert.Error(t, err)
19+
mutex, err := New(cli, "test", 1)
20+
assert.NoError(t, err)
21+
22+
ctx := context.Background()
23+
err = mutex.Lock(ctx)
24+
assert.NoError(t, err)
25+
err = mutex.Unlock(ctx)
26+
assert.NoError(t, err)
27+
}

0 commit comments

Comments
 (0)