Skip to content

Commit

Permalink
fix: Unstable key generation with provider states #1717
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Sep 21, 2023
1 parent c6efac9 commit 5d29116
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ data class ProviderState @JvmOverloads constructor(val name: String?, val params

fun uniqueKey(): Int {
val builder = HashCodeBuilder().append(name)
for (param in params) {
builder.append(param.key)
for (param in params.keys.sorted()) {
builder.append(param)
}
return builder.toHashCode()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package au.com.dius.pact.core.model

import spock.lang.Issue
import spock.lang.Specification
import spock.lang.Unroll

Expand Down Expand Up @@ -41,4 +42,21 @@ class ProviderStateSpec extends Specification {
state1.uniqueKey() != state3.uniqueKey()
state1.uniqueKey() != state4.uniqueKey()
}

@Issue("#1717")
def 'uniqueKey should be deterministic'() {
given:
def state = new ProviderState('a user profile exists', [
email_address: '[email protected]',
family_name: 'Test'
])
def state2 = new ProviderState('a user profile exists', [
family_name: 'Test',
email_address: '[email protected]'
])

expect:
state.uniqueKey() == state.uniqueKey()
state.uniqueKey() == state2.uniqueKey()
}
}

0 comments on commit 5d29116

Please sign in to comment.