2022-11-28 09:59:43 +00:00
|
|
|
package bundle
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2024-03-25 14:18:47 +00:00
|
|
|
"github.com/databricks/cli/libs/diag"
|
2022-11-28 09:59:43 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
type testMutator struct {
|
|
|
|
applyCalled int
|
|
|
|
nestedMutators []Mutator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *testMutator) Name() string {
|
|
|
|
return "test"
|
|
|
|
}
|
|
|
|
|
2024-03-25 14:18:47 +00:00
|
|
|
func (t *testMutator) Apply(ctx context.Context, b *Bundle) diag.Diagnostics {
|
2022-11-28 09:59:43 +00:00
|
|
|
t.applyCalled++
|
2023-05-24 12:45:19 +00:00
|
|
|
return Apply(ctx, b, Seq(t.nestedMutators...))
|
2022-11-28 09:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMutator(t *testing.T) {
|
|
|
|
nested := []*testMutator{
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
}
|
|
|
|
|
|
|
|
m := &testMutator{
|
|
|
|
nestedMutators: []Mutator{
|
|
|
|
nested[0],
|
|
|
|
nested[1],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-11-15 14:03:36 +00:00
|
|
|
b := &Bundle{}
|
2024-03-25 14:18:47 +00:00
|
|
|
diags := Apply(context.Background(), b, m)
|
|
|
|
assert.NoError(t, diags.Error())
|
2022-11-28 09:59:43 +00:00
|
|
|
|
|
|
|
assert.Equal(t, 1, m.applyCalled)
|
|
|
|
assert.Equal(t, 1, nested[0].applyCalled)
|
|
|
|
assert.Equal(t, 1, nested[1].applyCalled)
|
|
|
|
}
|