forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inmem_test.go
52 lines (41 loc) · 999 Bytes
/
inmem_test.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
package state
import (
"testing"
)
func TestInmemState(t *testing.T) {
TestState(t, &InmemState{state: TestStateInitial()})
}
func TestInmemState_impl(t *testing.T) {
var _ StateReader = new(InmemState)
var _ StateWriter = new(InmemState)
var _ StatePersister = new(InmemState)
var _ StateRefresher = new(InmemState)
}
func TestInmemLocker(t *testing.T) {
inmem := &InmemState{state: TestStateInitial()}
// test that it correctly wraps the inmem state
s := &inmemLocker{InmemState: inmem}
TestState(t, s)
info := NewLockInfo()
id, err := s.Lock(info)
if err != nil {
t.Fatal(err)
}
if id == "" {
t.Fatal("no lock id from state lock")
}
// locking again should fail
_, err = s.Lock(NewLockInfo())
if err == nil {
t.Fatal("state locked while locked")
}
if err.(*LockError).Info.ID != id {
t.Fatal("wrong lock id from lock failure")
}
if err := s.Unlock(id); err != nil {
t.Fatal(err)
}
if _, err := s.Lock(NewLockInfo()); err != nil {
t.Fatal(err)
}
}