Skip to content

Commit

Permalink
noCopy & clone fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Jan 13, 2023
1 parent 5b0e070 commit 6420280
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
15 changes: 8 additions & 7 deletions chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ import (
// subsequent failures will be ignored not only in parent chain, but also
// in all newly created child chains
type chain struct {
noCopy noCopy

context AssertionContext
handler AssertionHandler
severity AssertionSeverity
failCb func()
failBit bool

failCb func()
failBit bool
}

// Construct chain using config.
Expand Down Expand Up @@ -140,12 +143,10 @@ func (c *chain) setResponse(resp *Response) {
// Create a clone of the chain.
// Modifications of the clone wont affect the original.
func (c *chain) clone() *chain {
ret := *c

ret.context.Path = nil
ret.context.Path = append(ret.context.Path, c.context.Path...)
copy := *c //nolint
copy.context.Path = append(([]string)(nil), c.context.Path...)

return &ret
return &copy
}

// Append string to chain path.
Expand Down
14 changes: 6 additions & 8 deletions expect.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,12 @@ func (e *Expect) Env() *Environment {
}

func (e *Expect) clone() *Expect {
var copy Expect

copy.config = e.config
copy.chain = e.chain.clone()
copy.builders = append(copy.builders, e.builders...)
copy.matchers = append(copy.matchers, e.matchers...)

return &copy
return &Expect{
config: e.config,
chain: e.chain.clone(),
builders: append(([]func(*Request))(nil), e.builders...),
matchers: append(([]func(*Response))(nil), e.matchers...),
}
}

// Builder returns a copy of Expect instance with given builder attached to it.
Expand Down
4 changes: 3 additions & 1 deletion websocket_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (

// WebsocketMessage provides methods to inspect message read from WebSocket connection.
type WebsocketMessage struct {
chain *chain
noCopy noCopy
chain *chain

typ int
content []byte
closeCode int
Expand Down

0 comments on commit 6420280

Please sign in to comment.