-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlock_test.go
More file actions
42 lines (32 loc) · 798 Bytes
/
lock_test.go
File metadata and controls
42 lines (32 loc) · 798 Bytes
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
package etcd
import (
"os/exec"
"testing"
)
func init() {
_, err := exec.Command("etcd", "--version").Output()
if err != nil {
log.Fatal(err)
}
}
func TestAcquireReleaseLock(t *testing.T) {
startEtcd()
defer stopEtcd()
etcdClient := NewClient([]string{"http://localhost:4001"})
err := AcquireLock(etcdClient, "/lock", 10)
if err != nil {
t.Fatalf("Unexpected error '%v'", err)
}
value := Get(etcdClient, "/lock")
if value == "" {
t.Fatalf("Expected '%v' arguments but returned '%v'", "locked", value)
}
if value != "locked" {
t.Fatalf("Expected '%v' arguments but returned '%v'", "locked", value)
}
ReleaseLock(etcdClient)
value = Get(etcdClient, "/lock")
if value != "released" {
t.Fatalf("Expected '%v' arguments but returned '%v'", "released", value)
}
}