state: InmemState
This commit is contained in:
parent
5555059540
commit
3bf59183b8
|
@ -0,0 +1,27 @@
|
||||||
|
package state
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
)
|
||||||
|
|
||||||
|
// InmemState is an in-memory state storage.
|
||||||
|
type InmemState struct {
|
||||||
|
state *terraform.State
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *InmemState) State() *terraform.State {
|
||||||
|
return s.state
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *InmemState) RefreshState() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *InmemState) WriteState(state *terraform.State) error {
|
||||||
|
s.state = state
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *InmemState) PersistState() error {
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
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)
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -49,6 +50,11 @@ func (s *LocalState) WriteState(state *terraform.State) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create all the directories
|
||||||
|
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
f, err := os.Create(path)
|
f, err := os.Create(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -26,11 +26,12 @@ func TestState(t *testing.T, s interface{}) {
|
||||||
|
|
||||||
// current will track our current state
|
// current will track our current state
|
||||||
current := TestStateInitial()
|
current := TestStateInitial()
|
||||||
current.Serial++
|
|
||||||
|
|
||||||
// Check that the initial state is correct
|
// Check that the initial state is correct
|
||||||
if !reflect.DeepEqual(reader.State(), current) {
|
state := reader.State()
|
||||||
t.Fatalf("not initial: %#v\n\n%#v", reader.State(), current)
|
current.Serial = state.Serial
|
||||||
|
if !reflect.DeepEqual(state, current) {
|
||||||
|
t.Fatalf("not initial: %#v\n\n%#v", state, current)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write a new state and verify that we have it
|
// Write a new state and verify that we have it
|
||||||
|
|
Loading…
Reference in New Issue