terraform: State.IsEmpty
This commit is contained in:
parent
6cd5c894e8
commit
330364f668
|
@ -125,6 +125,15 @@ func (s *State) ModuleOrphans(path []string, c *config.Config) [][]string {
|
|||
return orphans
|
||||
}
|
||||
|
||||
// Empty returns true if the state is empty.
|
||||
func (s *State) Empty() bool {
|
||||
if s == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return len(s.Modules) == 0
|
||||
}
|
||||
|
||||
// IsRemote returns true if State represents a state that exists and is
|
||||
// remote.
|
||||
func (s *State) IsRemote() bool {
|
||||
|
@ -282,7 +291,7 @@ func (r *RemoteState) deepcopy() *RemoteState {
|
|||
}
|
||||
|
||||
func (r *RemoteState) Empty() bool {
|
||||
return r.Type == "" && len(r.Config) == 0
|
||||
return r == nil || r.Type == ""
|
||||
}
|
||||
|
||||
func (r *RemoteState) Equals(other *RemoteState) bool {
|
||||
|
|
|
@ -312,6 +312,42 @@ func TestInstanceStateEqual(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestStateEmpty(t *testing.T) {
|
||||
cases := []struct {
|
||||
In *State
|
||||
Result bool
|
||||
}{
|
||||
{
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
{
|
||||
&State{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
&State{
|
||||
Remote: &RemoteState{Type: "foo"},
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{},
|
||||
},
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
if tc.In.Empty() != tc.Result {
|
||||
t.Fatalf("bad %d %#v:\n\n%#v", i, tc.Result, tc.In)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStateIsRemote(t *testing.T) {
|
||||
cases := []struct {
|
||||
In *State
|
||||
|
|
Loading…
Reference in New Issue