Like enter(), but it replaces last element of the path instead appending to it. Must be called between enter() and leave().
(name string, args ...interface{})
| 334 | // Like enter(), but it replaces last element of the path instead appending to it. |
| 335 | // Must be called between enter() and leave(). |
| 336 | func (c *chain) replace(name string, args ...interface{}) *chain { |
| 337 | if chainValidation { |
| 338 | func() { |
| 339 | c.mu.Lock() |
| 340 | defer c.mu.Unlock() |
| 341 | |
| 342 | if c.state != stateEntered { |
| 343 | panic("replace allowed only between enter/leave") |
| 344 | } |
| 345 | if len(c.context.Path) == 0 { |
| 346 | panic("replace allowed only if path is non-empty") |
| 347 | } |
| 348 | if len(c.context.AliasedPath) == 0 { |
| 349 | panic("replace allowed only if aliased path is non-empty") |
| 350 | } |
| 351 | }() |
| 352 | } |
| 353 | |
| 354 | chainCopy := c.clone() |
| 355 | |
| 356 | chainCopy.state = stateEntered |
| 357 | if len(chainCopy.context.Path) != 0 { |
| 358 | last := len(chainCopy.context.Path) - 1 |
| 359 | chainCopy.context.Path[last] = fmt.Sprintf(name, args...) |
| 360 | } |
| 361 | if len(chainCopy.context.AliasedPath) != 0 { |
| 362 | last := len(chainCopy.context.AliasedPath) - 1 |
| 363 | chainCopy.context.AliasedPath[last] = fmt.Sprintf(name, args...) |
| 364 | } |
| 365 | |
| 366 | return chainCopy |
| 367 | } |
| 368 | |
| 369 | // Finalize assertion. |
| 370 | // Report success of failure to AssertionHandler. |