Skip to content

Commit

Permalink
Add unit tests for runtime API conversions
Browse files Browse the repository at this point in the history
Signed-off-by: Alper Rifat Ulucinar <[email protected]>
  • Loading branch information
ulucinar committed May 7, 2024
1 parent b2b515f commit 83e4f07
Show file tree
Hide file tree
Showing 6 changed files with 824 additions and 11 deletions.
19 changes: 15 additions & 4 deletions pkg/config/conversion/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,14 @@ func newIdentityConversion(sourceVersion, targetVersion string, excludePaths ...
// NewIdentityConversionExpandPaths returns a new Conversion from the specified
// sourceVersion of an API to the specified targetVersion, which copies the
// identical paths from the source to the target. excludePaths can be used
// to ignore certain field paths while copying.
// The field paths in excludePath are sorted in lexical order and expanded
// by default into spec.forProvider, spec.initProvider and
// status.atProvider paths.
// to ignore certain field paths while copying. Exclude paths must be specified
// in standard crossplane-runtime fieldpath library syntax, i.e., with proper
// indices for traversing map and slice types (e.g., a.b[*].c).
// The field paths in excludePaths are sorted in lexical order and are prefixed
// with each of the path prefixes specified with pathPrefixes. So if an
// exclude path "x" is specified with the prefix slice ["a", "b"], then
// paths a.x and b.x will both be skipped while copying fields from a source to
// a target.
func NewIdentityConversionExpandPaths(sourceVersion, targetVersion string, pathPrefixes []string, excludePaths ...string) Conversion {
return newIdentityConversion(sourceVersion, targetVersion, ExpandParameters(pathPrefixes, excludePaths...)...)
}
Expand All @@ -296,3 +300,10 @@ func ExpandParameters(prefixes []string, excludePaths ...string) []string {
}
return r
}

// DefaultPathPrefixes returns the list of the default path prefixes for
// excluding paths in the identity conversion. The returned value is
// ["spec.forProvider", "spec.initProvider", "status.atProvider"].
func DefaultPathPrefixes() []string {
return []string{"spec.forProvider", "spec.initProvider", "status.atProvider"}
}
Loading

0 comments on commit 83e4f07

Please sign in to comment.