terraform: State.IsRemote

This commit is contained in:
Mitchell Hashimoto 2015-02-22 10:29:42 -08:00
parent 3550f7ac3a
commit 6cd5c894e8
2 changed files with 44 additions and 0 deletions

View File

@ -125,6 +125,22 @@ func (s *State) ModuleOrphans(path []string, c *config.Config) [][]string {
return orphans
}
// IsRemote returns true if State represents a state that exists and is
// remote.
func (s *State) IsRemote() bool {
if s == nil {
return false
}
if s.Remote == nil {
return false
}
if s.Remote.Type == "" {
return false
}
return true
}
// RootModule returns the ModuleState for the root module
func (s *State) RootModule() *ModuleState {
root := s.ModuleByPath(rootModulePath)

View File

@ -312,6 +312,34 @@ func TestInstanceStateEqual(t *testing.T) {
}
}
func TestStateIsRemote(t *testing.T) {
cases := []struct {
In *State
Result bool
}{
{
nil,
false,
},
{
&State{},
false,
},
{
&State{
Remote: &RemoteState{Type: "foo"},
},
true,
},
}
for i, tc := range cases {
if tc.In.IsRemote() != tc.Result {
t.Fatalf("bad %d %#v:\n\n%#v", i, tc.Result, tc.In)
}
}
}
func TestInstanceState_MergeDiff(t *testing.T) {
is := InstanceState{
ID: "foo",