Hi do we have an example to use consumer version s...
# pact-jvm
j
Hi do we have an example to use consumer version selector in kotlin? Thanks. Where in the code should i put this in ?
Copy code
@PactBrokerConsumerVersionSelectors
fun consumerVersionSelectors(): SelectorBuilder = SelectorBuilder()
        .branch("main")
        .environment("prod")
        .environment("qa")
        .environment("int")
u
You can put in either as a test method or add to the companion object of the test. See https://github.com/pact-foundation/pact-jvm/blob/master/provider/junit5/src/test/k[…]/dius/pact/provider/junit5/ConsumerVersionSelectorKotlinTest.kt for examples
j
Thanks. I give it a try
u
You don't need
called = true
or the
companion object
, those were just for that test
Do you have any Pacts with the branch set as
master
?
j
yup i believe so
message has been deleted
the code keep saying consumerVersionSelectors is never used. is that right?
u
It should be called, but at runtime so the IDE won't know that.
we will need to look at the debug logs to see what selectors are being sent to the broker
j
i see this `160517.740 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-0 >> "[\r][\n]" 160517.740 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-0 >> "{"consumerVersionSelectors":[{"branch":"master"}],"includePendingStatus":false}" 160518.004 [Test worker] DEBUG org.apache.hc.client5.http.wire - http-outgoing-0 << "HTTP/1.1 200 OK[\r][\n]"
whole debug log
u
Ok, looks like those selectors are working correctly
j
but i dont quite understand at pactflow everything seem to be ticked off
message has been deleted
like would i expect that only master get verified?
i see all the consumers with the provider branches . i thought would only be master. correct me if i am not understanding something right
u
The pact at https://airwallex.pactflow.io/pacts/provider/SmeApiPactProvider/consumer/ApprovalsApproveMutationPactConsumer/pact-version/5cff543e5114655ded425a6a84b03457f5f9b468 is being verified because the pact content belongs to the consumer version matching the following criterion:\n * latest version from branch 'master' (9ebc76da)
That is in the logs, so the selectors are working
You can see that version is the one in your screenshot
j
but why does all the consumer version seem to be "verified"
from the pactflow ui
u
I have just deleted the log, in case it has sensitive info in it
j
thanks!
could you help me understand a little how i should read the pactflow UI
to match w the selectors
u
They will all be verified if the Pacts are all the same
j
i see but if only master is unique and the rest is different
only master will have a tick?
u
The Pact broker creates versions of Pacts based on their contents, so if they have the same contents, they are the same Pact
j
got it
u
Yes, if master was different, it should only be verified
j
For this unit test because it is always needing a pact flow token. Is there a good practice i can run it locally? It works well in my pipeline but im just wondering if there is a good way to run it locally.
or user always have to manually set the environment variable to make it work
u
If the token is set with an environment variable, you can use that locally.
It is the safest way, because the token will be gone when you close your console
j
the error message it returns for incorrect token dosen look very indicative to user? is there a way i can make it more explicit?
Copy code
Parameter specified as non-null is null: method com.airwallex.expenseservice.graphql.MutationPactTest.setUp, parameter context
java.lang.NullPointerException: Parameter specified as non-null is null: method com.airwallex.expenseservice.graphql.MutationPactTest.setUp, parameter context
	at com.airwallex.expenseservice.graphql.MutationPactTest.setUp(MutationPactTest.kt)
i deleted my code snippets above in case there is something sensitve fyi
u
That is Kotlin failing because the parameter is null, not much we can so about that message. You can add
?
to the type of the context, but it will be null in the method
I don't think the context can be used in the setup, it is not created yet
j
Would it be advisable to use the read only token for running locally?
1
I have published a pact with a different provider version and branch and tests mentioned it is published but i dont see it in pactflow. Is there a reason why? Eg i published one for master branch but i still see the feature branch name?
message has been deleted
@uglyog is pact having some issues w the publishing? I see for provider but pactflow is just not updated.
Copy code
worker","logger":"au.com.dius.pact.provider.DefaultVerificationReporter","message":"Published verification result of \u0027Ok(interactionIds\u003d[43fe5659a8234dd73c1f537b59b7ccf92091e6c8])\u0027 for consumer \u0027Consumer(name\u003dApprovalsApproveMutationPactConsumer)\u0027","context":"default"}
even for a similar use case of a branch that i was doing yesterday. or somehow i overlooked something..hmm
u
If you go to the Matrix tab, you will see all the publish and verification details
Eg i published one for master branch
How are you setting the provider branch?
j
in the pipeline. upon investigating further could be the tests are not run or skipped at times . more of configuration issue on my end. thanks for checking
b
Would it be advisable to use the read only token for running locally?
@James Weng yes.
j
Yeap this is what we did. Thanks
👍🏼 1
b
And use the system account token for CI/CD