MCPcopy Create free account
hub / github.com/compose-spec/compose-go / TestRegisterDefaultValue

Function TestRegisterDefaultValue

transform/defaults_test.go:130–318  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

128}
129
130func TestRegisterDefaultValue(t *testing.T) {
131 // Save original transformers, so as not to break possible other tests
132 originalTransformers := make(map[tree.Path]Func)
133 for k, v := range DefaultValues {
134 originalTransformers[k] = v
135 }
136 t.Cleanup(func() {
137 DefaultValues = originalTransformers
138 })
139
140 // Register the function
141 RegisterDefaultValue("services.*.ports.*", exampleEnhancedPortDefaults)
142
143 testCases := []struct {
144 name string
145 inputYAML string
146 expectedYAML string
147 }{
148 {
149 name: "basic port with defaults and auto-generated name",
150 inputYAML: `
151services:
152 web:
153 ports:
154 - target: 80
155`,
156 expectedYAML: `
157services:
158 web:
159 ports:
160 - target: 80
161 protocol: tcp
162 mode: ingress
163 name: http
164 x-metrics-enabled: true
165 x-metrics-path: /metrics
166`,
167 },
168 {
169 name: "port with https protocol and app_protocol",
170 inputYAML: `
171services:
172 web:
173 ports:
174 - target: 443
175 protocol: https
176`,
177 expectedYAML: `
178services:
179 web:
180 ports:
181 - target: 443
182 protocol: https
183 app_protocol: http2
184 mode: ingress
185 name: https
186 x-metrics-enabled: true
187 x-metrics-path: /metrics

Callers

nothing calls this directly

Calls 2

RegisterDefaultValueFunction · 0.85
SetDefaultValuesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…