github.com/akazakov/terraform@v0.5.2-0.20160205142716-097441beafdf/state/cache_test.go (about) 1 package state 2 3 import ( 4 "os" 5 "reflect" 6 "testing" 7 ) 8 9 func TestCacheState(t *testing.T) { 10 cache := testLocalState(t) 11 durable := testLocalState(t) 12 defer os.Remove(cache.Path) 13 defer os.Remove(durable.Path) 14 15 TestState(t, &CacheState{ 16 Cache: cache, 17 Durable: durable, 18 }) 19 } 20 21 func TestCacheState_persistDurable(t *testing.T) { 22 cache := testLocalState(t) 23 durable := testLocalState(t) 24 defer os.Remove(cache.Path) 25 defer os.Remove(durable.Path) 26 27 cs := &CacheState{ 28 Cache: cache, 29 Durable: durable, 30 } 31 32 state := cache.State() 33 state.Modules = nil 34 if err := cs.WriteState(state); err != nil { 35 t.Fatalf("err: %s", err) 36 } 37 38 if reflect.DeepEqual(cache.State(), durable.State()) { 39 t.Fatal("cache and durable should not be the same") 40 } 41 42 if err := cs.PersistState(); err != nil { 43 t.Fatalf("err: %s", err) 44 } 45 46 if !reflect.DeepEqual(cache.State(), durable.State()) { 47 t.Fatalf( 48 "cache and durable should be the same\n\n%#v\n\n%#v", 49 cache.State(), durable.State()) 50 } 51 } 52 53 func TestCacheState_impl(t *testing.T) { 54 var _ StateReader = new(CacheState) 55 var _ StateWriter = new(CacheState) 56 var _ StatePersister = new(CacheState) 57 var _ StateRefresher = new(CacheState) 58 }