Skip to content

Commit

Permalink
Revert "switch Response and HeaderBuilder Clones from doing shallow c…
Browse files Browse the repository at this point in the history
…lones when deep ones are not possible to panicking"

This reverts commit ed808db.
  • Loading branch information
aschmahmann committed Sep 19, 2023
1 parent ed808db commit be3f9e7
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions tooling/test/sugar.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (e ExpectBuilder) Validate(t *testing.T, res *http.Response, localReport Re
}

// Clone performs a deep clone of the ExpectBuilder
// Note: if there are unclonable components like [check.Check]s used in the inner header or body this will panic
// Note: if there are [check.Check]s used in the inner header or body components those are only shallowly cloned
func (e ExpectBuilder) Clone() ExpectValidator {
clone := ExpectBuilder{}
var clonedHeaders []HeaderBuilder
Expand All @@ -273,8 +273,16 @@ func (e ExpectBuilder) Clone() ExpectValidator {
clone.Body_ = body
case []byte:
clone.Body_ = body[:]
case check.CheckWithHint[string]:
clone.Body_ = body
case check.CheckWithHint[[]byte]:
clone.Body_ = body
case check.Check[string]:
clone.Body_ = body
case check.Check[[]byte]:
clone.Body_ = body
default:
panic("body must be string or []byte")
panic("body must be string, []byte, or a regular check")
}
return clone
}
Expand All @@ -301,8 +309,8 @@ func (e AllOfExpectBuilder) Validate(t *testing.T, res *http.Response, localRepo
}

// Clone performs a deep clone of the AllOfExpectBuilder
// Note: if there are unclonable components like [check.Check]s used in the header or body of the nested builders
// this will panic
// Note: if there are [check.Check]s used in the header or body components of the nested builders those are only
// shallowly cloned
func (e AllOfExpectBuilder) Clone() ExpectValidator {
var clonedInnerValidators []ExpectValidator
for _, eb := range e.Expect_ {
Expand Down Expand Up @@ -363,8 +371,8 @@ func (e AnyOfExpectBuilder) Validate(t *testing.T, res *http.Response, localRepo
}

// Clone performs a deep clone of the AnyOfExpectBuilder
// Note: if there are unclonable components like [check.Check]s used in the header or body of the nested builders
// this will panic
// Note: if there are [check.Check]s used in the header or body components of the nested builders those are only
// shallowly cloned
func (e AnyOfExpectBuilder) Clone() ExpectValidator {
var clonedInnerBuilders []ExpectBuilder
for _, eb := range e.Expect_ {
Expand Down Expand Up @@ -460,13 +468,9 @@ func (h HeaderBuilder) Exists() HeaderBuilder {
return h.Not().IsEmpty()
}

// Clone performs a deep clone of the HeaderBuilder
// Note: if the Check_ field is not nil this will panic since that field cannot be deep cloned
// Clone performs a shallow clone of the HeaderBuilder
// Note: The Check field is an interface and as a result is just copied
func (h HeaderBuilder) Clone() HeaderBuilder {
if h.Check_ != nil {
panic("cannot clone a HeaderBuilder with a non-nil Check")
}

clone := HeaderBuilder{
Key_: h.Key_,
Value_: h.Key_,
Expand Down

0 comments on commit be3f9e7

Please sign in to comment.