MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / TestMapCollectionWithLookups

Function TestMapCollectionWithLookups

pkg/util/util_test.go:65–378  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

63}
64
65func TestMapCollectionWithLookups(t *testing.T) {
66 // model: A person works in the Sales Department in the Country of New Zealand
67 type Person struct {
68 ID string
69 FirstName string
70 LastName string
71 DepartmentID string
72 CountryID string
73 }
74
75 type Department struct {
76 ID string
77 Name string
78 }
79
80 departments := map[string]Department{
81 "S": {ID: "S", Name: "Sales"},
82 "M": {ID: "M", Name: "Marketing"},
83 }
84
85 type Country struct {
86 ID string
87 Name string
88 }
89
90 countries := map[string]Country{
91 "NZ": {ID: "NZ", Name: "New Zealand"},
92 "AU": {ID: "AU", Name: "Australia"},
93 }
94
95 people := []Person{
96 {ID: "1", FirstName: "John", LastName: "Smith", DepartmentID: "S", CountryID: "NZ"},
97 {ID: "2", FirstName: "Jane", LastName: "Doe", DepartmentID: "M", CountryID: "NZ"},
98 {ID: "3", FirstName: "Alan", LastName: "Walker", DepartmentID: "S", CountryID: "AU"},
99 }
100
101 type PersonWithCountryDepartment struct {
102 PersonID string
103 Name string
104 DepartmentName string
105 CountryName string
106 }
107
108 t.Run("typical with two lookups", func(t *testing.T) {
109 caches := util.MapCollectionCacheContainer{}
110
111 results, err := util.MapCollectionWithLookups(
112 &caches,
113 people,
114 func(p Person) []string { return []string{p.DepartmentID, p.CountryID} },
115 func(p Person, lookup []string) PersonWithCountryDepartment {
116 return PersonWithCountryDepartment{
117 PersonID: p.ID,
118 Name: fmt.Sprintf("%s %s", p.FirstName, p.LastName),
119 DepartmentName: lookup[0],
120 CountryName: lookup[1],
121 }
122 },

Callers

nothing calls this directly

Calls 2

MapCollectionWithLookupsFunction · 0.92
SliceTransformFunction · 0.92

Tested by

no test coverage detected