Skip to content

Commit

Permalink
chore(manifest): test each individual transformers (aws#2795)
Browse files Browse the repository at this point in the history
This PR tests each individual transformer. In addition, it also includes a small refactoring on basic transformer.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
  • Loading branch information
Lou1415926 authored and thrau committed Dec 9, 2022
1 parent 4c026cf commit 43841ec
Show file tree
Hide file tree
Showing 2 changed files with 778 additions and 36 deletions.
54 changes: 18 additions & 36 deletions internal/pkg/manifest/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,54 +300,36 @@ func (t efsVolumeConfigurationTransformer) Transformer(typ reflect.Type) func(ds
}
}

func transformPBasic() func(dst, src reflect.Value) error {
// NOTE: `dst` must be of kind reflect.Ptr.
return func(dst, src reflect.Value) error {
// This condition shouldn't ever be true. It's merely here for extra safety so that `src.IsNil` won't panic.
if src.Kind() != reflect.Ptr {
return nil
}

if src.IsNil() {
return nil
}

if dst.CanSet() {
dst.Set(src)
}
return nil
}
}

type basicTransformer struct{}

// Transformer returns custom merge logic for volume's fields.
func (t basicTransformer) Transformer(typ reflect.Type) func(dst, src reflect.Value) error {
if typ.Kind() == reflect.Slice {
return func(dst, src reflect.Value) error {
// This condition shouldn't ever be true. It's merely here for extra safety so that `src.IsNil` won't panic.
if src.Kind() != reflect.Slice {
return nil
}

if src.IsNil() {
return nil
}

if dst.CanSet() {
dst.Set(src)
}

return nil
}
return transformPBasicOrSlice
}

if typ.Kind() == reflect.Ptr {
for _, k := range basicKinds {
if typ.Elem().Kind() == k {
return transformPBasic()
return transformPBasicOrSlice
}
}
}
return nil
}

func transformPBasicOrSlice(dst, src reflect.Value) error {
// This condition shouldn't ever be true. It's merely here for extra safety so that `src.IsNil` won't panic.
if src.Kind() != reflect.Ptr && src.Kind() != reflect.Slice {
return nil
}

if src.IsNil() {
return nil
}

if dst.CanSet() {
dst.Set(src)
}
return nil
}
Loading

0 comments on commit 43841ec

Please sign in to comment.