github.com/databricks/cli@v0.203.0/bundle/mutator_test.go (about)

     1  package bundle
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  type testMutator struct {
    11  	applyCalled    int
    12  	nestedMutators []Mutator
    13  }
    14  
    15  func (t *testMutator) Name() string {
    16  	return "test"
    17  }
    18  
    19  func (t *testMutator) Apply(ctx context.Context, b *Bundle) error {
    20  	t.applyCalled++
    21  	return Apply(ctx, b, Seq(t.nestedMutators...))
    22  }
    23  
    24  func TestMutator(t *testing.T) {
    25  	nested := []*testMutator{
    26  		{},
    27  		{},
    28  	}
    29  
    30  	m := &testMutator{
    31  		nestedMutators: []Mutator{
    32  			nested[0],
    33  			nested[1],
    34  		},
    35  	}
    36  
    37  	bundle := &Bundle{}
    38  	err := Apply(context.Background(), bundle, m)
    39  	assert.NoError(t, err)
    40  
    41  	assert.Equal(t, 1, m.applyCalled)
    42  	assert.Equal(t, 1, nested[0].applyCalled)
    43  	assert.Equal(t, 1, nested[1].applyCalled)
    44  }