mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
test: add testutil for mutation tracker
This change provides a common test util for a mutation tracker stub. This is intended to reduce the duplicated boilerplate as additional filters implement the TrackableFilter interface.
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
func run(input string, f kio.Filter) (string, error) {
|
||||
@@ -46,3 +47,32 @@ func RunFilterE(t *testing.T, input string, f kio.Filter) (string, error) {
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
|
||||
type SetValueArg struct {
|
||||
Key string
|
||||
Value string
|
||||
Tag string
|
||||
NodePath []string
|
||||
}
|
||||
|
||||
// MutationTrackerStub to help stub a mutation tracker for kio.TrackableFilter
|
||||
type MutationTrackerStub struct {
|
||||
setValueArgs []SetValueArg
|
||||
}
|
||||
|
||||
func (mts *MutationTrackerStub) MutationTracker(key, value, tag string, node *yaml.RNode) {
|
||||
mts.setValueArgs = append(mts.setValueArgs, SetValueArg{
|
||||
Key: key,
|
||||
Value: value,
|
||||
Tag: tag,
|
||||
NodePath: node.FieldPath(),
|
||||
})
|
||||
}
|
||||
|
||||
func (mts *MutationTrackerStub) SetValueArgs() []SetValueArg {
|
||||
return mts.setValueArgs
|
||||
}
|
||||
|
||||
func (mts *MutationTrackerStub) Reset() {
|
||||
mts.setValueArgs = nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user