Skip to content

Commit 5d29116

Browse files
committedSep 21, 2023
fix: Unstable key generation with provider states #1717
1 parent c6efac9 commit 5d29116

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed
 

‎core/model/src/main/kotlin/au/com/dius/pact/core/model/ProviderState.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ data class ProviderState @JvmOverloads constructor(val name: String?, val params
3838

3939
fun uniqueKey(): Int {
4040
val builder = HashCodeBuilder().append(name)
41-
for (param in params) {
42-
builder.append(param.key)
41+
for (param in params.keys.sorted()) {
42+
builder.append(param)
4343
}
4444
return builder.toHashCode()
4545
}

‎core/model/src/test/groovy/au/com/dius/pact/core/model/ProviderStateSpec.groovy

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package au.com.dius.pact.core.model
22

3+
import spock.lang.Issue
34
import spock.lang.Specification
45
import spock.lang.Unroll
56

@@ -41,4 +42,21 @@ class ProviderStateSpec extends Specification {
4142
state1.uniqueKey() != state3.uniqueKey()
4243
state1.uniqueKey() != state4.uniqueKey()
4344
}
45+
46+
@Issue("#1717")
47+
def 'uniqueKey should be deterministic'() {
48+
given:
49+
def state = new ProviderState('a user profile exists', [
50+
email_address: 'test@email.com',
51+
family_name: 'Test'
52+
])
53+
def state2 = new ProviderState('a user profile exists', [
54+
family_name: 'Test',
55+
email_address: 'test@email.com'
56+
])
57+
58+
expect:
59+
state.uniqueKey() == state.uniqueKey()
60+
state.uniqueKey() == state2.uniqueKey()
61+
}
4462
}

0 commit comments

Comments
 (0)
Please sign in to comment.