Skip to content

Commit

Permalink
Treat nil and empty string as equal when comparing scopes during merge (
Browse files Browse the repository at this point in the history
  • Loading branch information
TAGraves authored Jan 10, 2025
1 parent 4d096cb commit 7ce4800
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/testingschema/v1/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (t Test) Tag(key string, value any) Test {
}

func (t Test) Matches(other Test) bool {
if !stringPointerEquals(t.Scope, other.Scope) {
if !stringPointerEqualsTreatingEmptyAsNil(t.Scope, other.Scope) {
return false
}
if !stringPointerEquals(t.ID, other.ID) {
Expand Down Expand Up @@ -301,6 +301,20 @@ func stringPointerEquals(left *string, right *string) bool {
return *left == *right
}

func stringPointerEqualsTreatingEmptyAsNil(left *string, right *string) bool {
leftStr := ""
if left != nil {
leftStr = *left
}

rightStr := ""
if right != nil {
rightStr = *right
}

return leftStr == rightStr
}

func intPointerEquals(left *int, right *int) bool {
if (left == nil && right != nil) || (left != nil && right == nil) {
return false
Expand Down

0 comments on commit 7ce4800

Please sign in to comment.