github.com/koding/terraform@v0.6.4-0.20170608090606-5d7e0339779d/state/inmem_test.go (about)

     1  package state
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestInmemState(t *testing.T) {
     8  	TestState(t, &InmemState{state: TestStateInitial()})
     9  }
    10  
    11  func TestInmemState_impl(t *testing.T) {
    12  	var _ StateReader = new(InmemState)
    13  	var _ StateWriter = new(InmemState)
    14  	var _ StatePersister = new(InmemState)
    15  	var _ StateRefresher = new(InmemState)
    16  }
    17  
    18  func TestInmemLocker(t *testing.T) {
    19  	inmem := &InmemState{state: TestStateInitial()}
    20  	// test that it correctly wraps the inmem state
    21  	s := &inmemLocker{InmemState: inmem}
    22  	TestState(t, s)
    23  
    24  	info := NewLockInfo()
    25  
    26  	id, err := s.Lock(info)
    27  	if err != nil {
    28  		t.Fatal(err)
    29  	}
    30  
    31  	if id == "" {
    32  		t.Fatal("no lock id from state lock")
    33  	}
    34  
    35  	// locking again should fail
    36  	_, err = s.Lock(NewLockInfo())
    37  	if err == nil {
    38  		t.Fatal("state locked while locked")
    39  	}
    40  
    41  	if err.(*LockError).Info.ID != id {
    42  		t.Fatal("wrong lock id from lock failure")
    43  	}
    44  
    45  	if err := s.Unlock(id); err != nil {
    46  		t.Fatal(err)
    47  	}
    48  
    49  	if _, err := s.Lock(NewLockInfo()); err != nil {
    50  		t.Fatal(err)
    51  	}
    52  }