// Nested plan (plan as resource) that is valid
Nested plan (plan as resource) that is valid
// Nested plan ( plan as resource ) that is valid
func TestNestedPlan(t *testing.T) {
	r := &testutils.MockRunner{Output: "", Err: nil}
	b := NewBuilder("plan-1")
	b2 := NewBuilder("plan-1-1")
	b2.AddResource("bottom-1",
		&testResource{
			ID:                   "bottom-1",
			StatesShouldNotMatch: true})
	b2.AddResource("middle-1",
		&testResource{
			ID:                   "middle-1",
			StatesShouldNotMatch: true}, DependOn("bottom-1"))
	p11, err := b2.Plan()
	assert.NoError(t, err)
	b.AddResource("plan-1-1", &p11)
	b.AddResource("middle-2",
		&testResource{
			ID:                   "middle-2",
			StatesShouldNotMatch: true,
			ApplyShouldError:     true}, DependOn("plan-1-1"))
	b.AddResource("top",
		&testResource{
			ID:                   "top",
			StatesShouldNotMatch: true}, DependOn("plan-1-1", "middle-2"))
	assert.Equal(t, 0, len(b.Errors()))
	p, err := b.Plan()
	assert.NoError(t, err)
	diff := Diff{
		CurrentState: State(map[string]interface{}{
			"plan-1-1": State(map[string]interface{}{
				"bottom-1": State(map[string]interface{}{"bstate": 2}),
				"middle-1": State(map[string]interface{}{"m1state": 3})}),
			"middle-2": State(map[string]interface{}{"m2state": 4}),
			"top":      State(map[string]interface{}{"tstate": 5})}),
		InvalidatedDeps: []Resource{}}
	propagate, err := p.Apply(r, diff)
	assert.Error(t, err)
	assert.False(t, propagate)
	plan11 := ValidityTree{
		ResourceID:     "plan-1-1",
		ValidityStatus: Valid,
		Reason:         None,
		Updated:        true,
		Dependencies:   []ValidityTree{}}
	mid2 := ValidityTree{
		ResourceID:     "middle-2",
		ValidityStatus: Invalid,
		Reason:         ApplyError,
		ObservedError:  "Apply failed",
		Dependencies:   []ValidityTree{plan11}}
	top := ValidityTree{
		ResourceID:     "top",
		ValidityStatus: Invalid,
		Reason:         DependencyInvalid,
		Dependencies:   []ValidityTree{mid2, plan11}}
	plan := ValidityTree{
		ResourceID:     "plan-1",
		ValidityStatus: Invalid,
		Reason:         ChildInvalid,
		ObservedError:  "Apply failed because a child failed",
		Dependencies:   []ValidityTree{},
		Children:       []ValidityTree{top}}
	assert.Equal(t, plan, err)
	fmt.Printf("ERR: %v, ETREE: %s\n", err, err.(ValidityTree).ToJSON())
}
func TestNestedPlan ( t * testing . T ) { r := & testutils . MockRunner { Output : " " , Err : nil } b := NewBuilder ( " " ) b2 := NewBuilder ( " " ) b2 . AddResource ( " " , & testResource { ID : " " , StatesShouldNotMatch : true } ) b2 . AddResource ( " " , & testResource { ID : " " , StatesShouldNotMatch : true } , DependOn ( " " ) ) p11 , err := b2 . Plan ( ) assert . NoError ( t , err ) b . AddResource ( " " , & p11 ) b . AddResource ( " " , & testResource { ID : " " , StatesShouldNotMatch : true , ApplyShouldError : true } , DependOn ( " " ) ) b . AddResource ( " " , & testResource { ID : " " , StatesShouldNotMatch : true } , DependOn ( " " , " " ) ) assert . Equal ( t , 0 , len ( b . Errors ( ) ) ) p , err := b . Plan ( ) assert . NoError ( t , err ) diff := Diff { CurrentState : State ( map [ string ] interface { } { " " : State ( map [ string ] interface { } { " " : State ( map [ string ] interface { } { " " : 2 } ) , " " : State ( map [ string ] interface { } { " " : 3 } ) } ) , " " : State ( map [ string ] interface { } { " " : 4 } ) , " " : State ( map [ string ] interface { } { " " : 5 } ) } ) , InvalidatedDeps : [ ] Resource { } } propagate , err := p . Apply ( r , diff ) assert . Error ( t , err ) assert . False ( t , propagate ) plan11 := ValidityTree { ResourceID : " " , ValidityStatus : Valid , Reason : None , Updated : true , Dependencies : [ ] ValidityTree { } } mid2 := ValidityTree { ResourceID : " " , ValidityStatus : Invalid , Reason : ApplyError , ObservedError : " " , Dependencies : [ ] ValidityTree { plan11 } } top := ValidityTree { ResourceID : " " , ValidityStatus : Invalid , Reason : DependencyInvalid , Dependencies : [ ] ValidityTree { mid2 , plan11 } } plan := ValidityTree { ResourceID : " " , ValidityStatus : Invalid , Reason : ChildInvalid , ObservedError : " " , Dependencies : [ ] ValidityTree { } , Children : [ ] ValidityTree { top } } assert . Equal ( t , plan , err ) fmt . Printf ( " \n " , err , err . ( ValidityTree ) . ToJSON ( ) ) }
Nested plan (plan as resource) that is valid
Nested plan ( plan as resource ) that is valid