Skip to content

Commit

Permalink
IA-3814 Pact provider test (#928)
Browse files Browse the repository at this point in the history
* update deps

* Add pact provider tests.

* Add pact provider tests.

* Updated code to pull consumer contract from Pact broker.
Publish verification status to Pact broker.

* Rerun workflow

* Rerun workflow

* Attempt to fix build error.

* Attempt to fix build error.

* Debug library version conflicts.

* Revert changes

* Comment out unused dependencies for now.

* Updated merge strategy

* Clean up

* Moved provider test to separate project.

* Fixed missing import.

* Updated merge strategy and settings.

* revert cganges

* Add logback config.

* Updated logback version to 1.4.4

* revert to logback 1.2.11

* Updated logger to logback

* Updated slf4j to 2.0.6

* Clean up

* Add envvars for pact tests

* Rerun Jenkins test

* Refactored code.

* Refactored code

* Refactored code

* Updated dependencies

* Skip provider test in build.yml

* Refactored code.

* Refactored code.

* Refactored code.

* Clean up.

* Rerun failed Jenkins test

* Clean up.

* Updated workflow trigger.

Co-authored-by: Kai <[email protected]>
Co-authored-by: Ivan <[email protected]>
  • Loading branch information
3 people authored Jan 26, 2023
1 parent c450def commit 91469f6
Show file tree
Hide file tree
Showing 12 changed files with 900 additions and 4 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/verify_consumer_pacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Verify consumer pacts
# The purpose of this workflow is to verify Leo consumer contract
# using the Pact framework.
#
# The workflow requires Pact broker credentials
# - PACT_BROKER_USERNAME - the Pact Broker username
# - PACT_BROKER_PASSWORD - the Pact Broker password
on:
pull_request:
branches:
- develop
paths-ignore:
- 'README.md'
push:
branches:
- develop
paths-ignore:
- 'README.md'
env:
PACT_BROKER_URL: https://pact-broker.dsp-eng-tools.broadinstitute.org

jobs:
verify-consumer-pact:
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'

steps:
- name: Checkout current code
uses: actions/checkout@v3

- name: Extract branch
id: extract-branch
run: |
GITHUB_EVENT_NAME=${{ github.event_name }}
if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
GITHUB_REF=${{ github.ref }}
GITHUB_SHA=${{ github.sha }}
elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
GITHUB_REF=refs/heads/${{ github.head_ref }}
GITHUB_SHA=${{ github.event.pull_request.head.sha }}
else
echo "Failed to extract branch information"
exit 1
fi
echo "ref=$GITHUB_REF" >> $GITHUB_OUTPUT
echo "sha=$GITHUB_SHA" >> $GITHUB_OUTPUT
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "branch=${GITHUB_REF/refs\/heads\//""}" >> $GITHUB_OUTPUT
- name: Verify consumer pacts and publish verification status to Pact Broker
run: |
docker run --rm -v $PWD:/working \
-v jar-cache:/root/.ivy \
-v jar-cache:/root/.ivy2 \
-w /working \
-e BRANCH=${{ steps.extract-branch.outputs.branch }} \
-e GIT_SHA_SHORT=${{ steps.extract-branch.outputs.sha_short }} \
-e PACT_BROKER_URL=${{ env.PACT_BROKER_URL }} \
-e PACT_BROKER_USERNAME=${{ secrets.PACT_BROKER_USERNAME }} \
-e PACT_BROKER_PASSWORD=${{ secrets.PACT_BROKER_PASSWORD }} \
sbtscala/scala-sbt:openjdk-17.0.2_1.7.2_2.13.10 \
sbt "project pact4s" "testOnly *SamProviderSpec"
5 changes: 5 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ lazy val root = project
.settings(rootSettings: _*)
.withTestSettings

lazy val pact4s = project
.in(file("pact4s"))
.settings(pact4sSettings)
.dependsOn(root % "test->test;compile->compile")

Revolver.settings
Global / excludeLintKeys += debugSettings // To avoid lint warning

Expand Down
14 changes: 14 additions & 0 deletions pact4s/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<logger name="io.github.jbwheatley.pact4s.Pact4sLogger" level="INFO" />
<logger name="au.com.dius.pact.consumer" level="DEBUG"/>
<logger name="au.com.dius.pact.provider" level="DEBUG"/>

<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
198 changes: 198 additions & 0 deletions pact4s/src/test/resources/reference.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
googleServices {
appName = "firecloud:sam"
appsDomain = "dev.test.firecloud.org"
environment = "local"
pathToPem = "/etc/sam-account.pem"
pathToDefaultCredentialJson = "fakePath"
serviceAccountClientId = "109949113883754608360"
serviceAccountClientEmail = "[email protected]"
serviceAccountClientProject = "broad-dsde-dev"
subEmail = "[email protected]"
projectServiceAccount = "[email protected]"
terraGoogleOrgNumber = "mock-org-number" # This org number needs to match what is specified in workbench-libs/google/src/main/scala/org/broadinstitute/dsde/workbench/google/HttpGoogleProjectDAO.scala.getAncestry

groupSync {
pubSubProject = proj
pollInterval = 10ms
pollJitter = 0s
pubSubTopic = top
pubSubSubscription = sub
workerCount = 1
}

disableUsers {
pubSubProject = proj
pollInterval = 10ms
pollJitter = 0s
pubSubTopic = top
pubSubSubscription = sub
workerCount = 1
}

notifications {
project = proj
topicName = "notifications"
}

googleKeyCache {
bucketName = "my-test-bucket"
activeKeyMaxAge = 25000 #test objects default to Jan 1 1970. Cranking this value up allows for test keys to be seen as active
retiredKeyMaxAge = 25048

monitor {
pubSubProject = "broad-dsde-dev"
pollInterval = 1m
pollJitter = 10s
pubSubTopic = "sam-google-key-cache"
pubSubSubscription = "sam-google-key-cache-sub"
workerCount = 1
}
}

kms {
project = "broad-dsde-dev"
location = "global"
keyRingId = "not-actually-used"
keyId = "dockerhub-key"
rotationPeriod = "180 days"
}
}

db {
enabled=false
}

termsOfService {
enabled = false
version = 1
url = "app.terra.bio/#terms-of-service"
}

petServiceAccount {
googleProject = "my-pet-project"
serviceAccountUsers = ["[email protected]"]
}

testStuff = {
resourceTypes = {
testType = {
actionPatterns = {
alter_policies = {
description = ""
authDomainConstrainable = true
}
read_policies = {
description = ""
}
}
ownerRoleName = "owner"
roles = {
owner = {
roleActions = ["alter_policies", "read_policies"],
includedRoles = ["nonOwner"],
descendantRoles = {
otherType = ["owner"]
}
},
nonOwner = {
roleActions = []
}
}
reuseIds = false
}
}
# Test MRG in which to create managed identities
azure {
tenantId = "0cb7a640-45a2-4ed6-be9f-63519f86e04b"
subscriptionId = "3efc5bdf-be0e-44e7-b1d7-c08931e3c16c"
managedResourceGroupName = "mrg-terra-dev-previ-20220930130036"
}
}

// dummy value for testing only
oidc {
authorityEndpoint = "https://accounts.google.com"
oidcClientId = "some-client"
oidcClientSecret = "some-secret"
legacyGoogleClientId = "another-client"
}

liquibase {
changelog = "org/broadinstitute/dsde/sam/liquibase/changelog.xml"
initWithLiquibase = true
}

db {
enabled = true
enabled = ${?postgres.enabled}

sam_read {
poolName = "sam_read"
poolInitialSize = 5
poolMaxSize = 5
poolConnectionTimeoutMillis = 5000
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://localhost:5432/testdb?stringtype=unspecified"
user = "sam-test"
password = "sam-test"
}

sam_write {
poolName = "sam_write"
poolInitialSize = 5
poolMaxSize = 5
poolConnectionTimeoutMillis = 5000
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://localhost:5432/testdb?stringtype=unspecified"
user = "sam-test"
password = "sam-test"
}

// this background pool is used to test the status of a pool that cannot connect
sam_background {
poolName = "sam_background"
poolInitialSize = 5
poolMaxSize = 5
poolConnectionTimeoutMillis = 5000
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://does_not_exist/testdb?stringtype=unspecified"
user = "sam-test"
password = "sam-test"
}
}

scalikejdbc.global.loggingSQLAndTime {
enabled = false, # switch this to true to print sql
singleLineMode = true, # switch this to false to see stack trace information about where sql was executed
printUnprocessedStackTrace = false,
stackTraceDepth= 15,
logLevel = warn, # this is set to warn so we don't have to fiddle with logback settings too
warningEnabled = false,
warningThresholdMillis = 3000,
warningLogLevel = warn
}


dataStore {
live = postgres
}

termsOfService {
enabled = false
isGracePeriodEnabled = false
version = 0
url = "app.terra.bio/#terms-of-service"
}

admin {
superAdminsGroup = "[email protected]"
allowedAdminEmailDomains = ["test.firecloud.org"]
}

prometheus {
endpointPort = 0
}

oidc {
oidcClientId = "0"
}
3 changes: 3 additions & 0 deletions pact4s/src/test/resources/sam.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
prometheus {
endpointPort = 1
}
Loading

0 comments on commit 91469f6

Please sign in to comment.