2022-11-28 09:59:43 +00:00
|
|
|
package bundle
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
type testMutator struct {
|
|
|
|
applyCalled int
|
|
|
|
nestedMutators []Mutator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *testMutator) Name() string {
|
|
|
|
return "test"
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:45:19 +00:00
|
|
|
func (t *testMutator) Apply(ctx context.Context, b *Bundle) error {
|
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],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
bundle := &Bundle{}
|
2023-05-24 12:45:19 +00:00
|
|
|
err := Apply(context.Background(), bundle, m)
|
2022-11-28 09:59:43 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, 1, m.applyCalled)
|
|
|
|
assert.Equal(t, 1, nested[0].applyCalled)
|
|
|
|
assert.Equal(t, 1, nested[1].applyCalled)
|
|
|
|
}
|