// Last resource fails to apply; generate an error and note the invalid state
Last resource fails to apply; generate an error and note the invalid state
// Last resource fails to apply ; generate an error and note the invalid state
func TestStraightLinePlanLastApplyError(t *testing.T) {
	r := &testutils.MockRunner{Output: "", Err: nil}
	b := NewBuilder("plan-1")
	b.AddResource("resource-1", &testResource{ID: "resource-1"})
	b.AddResource("resource-2", &testResource{ID: "resource-2"}, DependOn("resource-1"))
	b.AddResource("resource-3",
		&testResource{
			ID:                   "resource-3",
			StatesShouldNotMatch: true,
			ApplyShouldError:     true}, DependOn("resource-2"))
	assert.Equal(t, 0, len(b.Errors()))
	p, err := b.Plan()
	assert.NoError(t, err)
	diff := Diff{
		CurrentState:    EmptyState,
		InvalidatedDeps: []Resource{}}
	propagate, err := p.Apply(r, diff)
	assert.Error(t, err)
	assert.False(t, propagate)
	res1 := ValidityTree{
		ResourceID:     "resource-1",
		ValidityStatus: Valid,
		Reason:         None,
		Dependencies:   []ValidityTree{}}
	res2 := ValidityTree{
		ResourceID:     "resource-2",
		ValidityStatus: Valid,
		Reason:         None,
		Dependencies:   []ValidityTree{res1}}
	res3 := ValidityTree{
		ResourceID:     "resource-3",
		ValidityStatus: Invalid,
		Reason:         ApplyError,
		ObservedError:  "Apply failed",
		Dependencies:   []ValidityTree{res2}}
	plan := ValidityTree{
		ResourceID:     "plan-1",
		ValidityStatus: Invalid,
		Reason:         ChildInvalid,
		ObservedError:  "Apply failed because a child failed",
		Dependencies:   []ValidityTree{},
		Children:       []ValidityTree{res3}}
	assert.Equal(t, plan, err)
}
func TestStraightLinePlanLastApplyError ( t * testing . T ) { r := & testutils . MockRunner { Output : " " , Err : nil } b := NewBuilder ( " " ) b . AddResource ( " " , & testResource { ID : " " } ) b . AddResource ( " " , & testResource { ID : " " } , DependOn ( " " ) ) b . AddResource ( " " , & testResource { ID : " " , StatesShouldNotMatch : true , ApplyShouldError : true } , DependOn ( " " ) ) assert . Equal ( t , 0 , len ( b . Errors ( ) ) ) p , err := b . Plan ( ) assert . NoError ( t , err ) diff := Diff { CurrentState : EmptyState , InvalidatedDeps : [ ] Resource { } } propagate , err := p . Apply ( r , diff ) assert . Error ( t , err ) assert . False ( t , propagate ) res1 := ValidityTree { ResourceID : " " , ValidityStatus : Valid , Reason : None , Dependencies : [ ] ValidityTree { } } res2 := ValidityTree { ResourceID : " " , ValidityStatus : Valid , Reason : None , Dependencies : [ ] ValidityTree { res1 } } res3 := ValidityTree { ResourceID : " " , ValidityStatus : Invalid , Reason : ApplyError , ObservedError : " " , Dependencies : [ ] ValidityTree { res2 } } plan := ValidityTree { ResourceID : " " , ValidityStatus : Invalid , Reason : ChildInvalid , ObservedError : " " , Dependencies : [ ] ValidityTree { } , Children : [ ] ValidityTree { res3 } } assert . Equal ( t , plan , err ) }
Last resource fails to apply; generate an error and note the invalid state
Last resource fails to apply ; generate an error and note the invalid state