Merge pull request #244 from smcavallo/reference_ptrvalue_helpers
add pointer helper functions for slices for referencers
This commit is contained in:
commit
3cd26cccdc
|
|
@ -56,6 +56,32 @@ func ToPtrValue(v string) *string {
|
|||
return &v
|
||||
}
|
||||
|
||||
// FromPtrValues adapts a slice of string pointer fields for use as CurrentValues.
|
||||
// NOTE: Do not use this utility function unless you have to.
|
||||
// Using pointer slices does not adhere to our current API practices.
|
||||
// The current use case is where generated code creates reference-able fields in a provider which are
|
||||
// string pointers and need to be resolved as part of `ResolveMultiple`
|
||||
func FromPtrValues(v []*string) []string {
|
||||
var res = make([]string, len(v))
|
||||
for i := 0; i < len(v); i++ {
|
||||
res[i] = FromPtrValue(v[i])
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// ToPtrValues adapts ResolvedValues for use as a slice of string pointer fields.
|
||||
// NOTE: Do not use this utility function unless you have to.
|
||||
// Using pointer slices does not adhere to our current API practices.
|
||||
// The current use case is where generated code creates reference-able fields in a provider which are
|
||||
// string pointers and need to be resolved as part of `ResolveMultiple`
|
||||
func ToPtrValues(v []string) []*string {
|
||||
var res = make([]*string, len(v))
|
||||
for i := 0; i < len(v); i++ {
|
||||
res[i] = ToPtrValue(v[i])
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// To indicates the kind of managed resource a reference is to.
|
||||
type To struct {
|
||||
Managed resource.Managed
|
||||
|
|
|
|||
|
|
@ -66,6 +66,26 @@ func TestToAndFromPtr(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestToAndFromPtrValues(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
want []string
|
||||
}{
|
||||
"Nil": {want: []string{}},
|
||||
"Zero": {want: []string{""}},
|
||||
"NonZero": {want: []string{"pointy"}},
|
||||
"Multiple": {want: []string{"pointy", "pointers"}},
|
||||
}
|
||||
for name, tc := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
got := FromPtrValues(ToPtrValues(tc.want))
|
||||
if diff := cmp.Diff(tc.want, got); diff != "" {
|
||||
t.Errorf("FromPtrValues(ToPtrValues(%s): -want, +got: %s", tc.want, diff)
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolve(t *testing.T) {
|
||||
errBoom := errors.New("boom")
|
||||
now := metav1.Now()
|
||||
|
|
|
|||
Loading…
Reference in New Issue