(t *testing.T)
| 128 | } |
| 129 | |
| 130 | func 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: ` |
| 151 | services: |
| 152 | web: |
| 153 | ports: |
| 154 | - target: 80 |
| 155 | `, |
| 156 | expectedYAML: ` |
| 157 | services: |
| 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: ` |
| 171 | services: |
| 172 | web: |
| 173 | ports: |
| 174 | - target: 443 |
| 175 | protocol: https |
| 176 | `, |
| 177 | expectedYAML: ` |
| 178 | services: |
| 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…