(rawConfig string, configType string)
| 210 | } |
| 211 | |
| 212 | func (tc *Tester) ensureConfigRunning(rawConfig string, configType string) error { |
| 213 | expectedBytes := []byte(prependCaddyFilePath(rawConfig)) |
| 214 | if configType != "json" { |
| 215 | adapter := caddyconfig.GetAdapter(configType) |
| 216 | if adapter == nil { |
| 217 | return fmt.Errorf("adapter of config type is missing: %s", configType) |
| 218 | } |
| 219 | expectedBytes, _, _ = adapter.Adapt([]byte(rawConfig), nil) |
| 220 | } |
| 221 | |
| 222 | var expected any |
| 223 | err := json.Unmarshal(expectedBytes, &expected) |
| 224 | if err != nil { |
| 225 | return err |
| 226 | } |
| 227 | |
| 228 | client := &http.Client{ |
| 229 | Timeout: tc.config.LoadRequestTimeout, |
| 230 | } |
| 231 | |
| 232 | fetchConfig := func(client *http.Client) any { |
| 233 | resp, err := client.Get(fmt.Sprintf("http://localhost:%d/config/", tc.config.AdminPort)) |
| 234 | if err != nil { |
| 235 | return nil |
| 236 | } |
| 237 | defer resp.Body.Close() |
| 238 | actualBytes, err := io.ReadAll(resp.Body) |
| 239 | if err != nil { |
| 240 | return nil |
| 241 | } |
| 242 | var actual any |
| 243 | err = json.Unmarshal(actualBytes, &actual) |
| 244 | if err != nil { |
| 245 | return nil |
| 246 | } |
| 247 | return actual |
| 248 | } |
| 249 | |
| 250 | for retries := 10; retries > 0; retries-- { |
| 251 | if reflect.DeepEqual(expected, fetchConfig(client)) { |
| 252 | return nil |
| 253 | } |
| 254 | time.Sleep(1 * time.Second) |
| 255 | } |
| 256 | tc.t.Errorf("POSTed configuration isn't active") |
| 257 | return errors.New("EnsureConfigRunning: POSTed configuration isn't active") |
| 258 | } |
| 259 | |
| 260 | const initConfig = `{ |
| 261 | admin localhost:%d |
no test coverage detected