From 9ee9b804c785fb1f47ddfde3705cd9b2f975fea6 Mon Sep 17 00:00:00 2001 From: oaljarrah Date: Wed, 4 Sep 2024 00:08:57 +0300 Subject: [PATCH] chore: test --- .github/workflows/selfserve-service-mock.yaml | 73 +++++++++++++++++++ .github/workflows/test.yaml | 9 +++ .../sdk/test/contract/extension/File.kt | 13 +--- .../templates/expediagroup-sdk/main.mustache | 2 +- .../templates/expediagroup-sdk/pom.mustache | 9 ++- 5 files changed, 94 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/selfserve-service-mock.yaml create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/selfserve-service-mock.yaml b/.github/workflows/selfserve-service-mock.yaml new file mode 100644 index 000000000..3850c431f --- /dev/null +++ b/.github/workflows/selfserve-service-mock.yaml @@ -0,0 +1,73 @@ +name: PR Check Tests Run +on: + workflow_call: + inputs: + repository: + description: 'Repository to checkout' + type: string + required: true + ref: + description: 'Branch or tag to checkout' + type: string + required: true + specs_path: + description: 'Path of the artifact to persist to' + type: string + default: '' + +jobs: + upload-specs: + uses: ./.github/workflows/selfserve-checkout-and-upload.yaml + with: + repository: ${{ inputs.repository }} + ref: "${{ github.head_ref || github.ref_name }}" + artifact_key: 'specs' + artifact_path: ${{ inputs.specs_path }} + mock: + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + name: specs + path: specs + - name: Download Latest Specmatic Executable + working-directory: specs + run: | + curl -s https://api.github.com/repos/znsio/specmatic/releases/latest \ + | grep "browser_download_url.*specmatic.jar" \ + | cut -d : -f 2,3 \ + | tr -d \" \ + | xargs curl -L -o specmatic.jar + - uses: actions/setup-node@v4 + with: + node-version: 18.18.2 + - uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'corretto' + - name: Parse Specs + working-directory: specs + run: | + spec=$(find . -maxdepth 1 -type f \( -name "*.yaml" -o -name "*.yml" \) | head -n 1) + + if [ ! -f $spec ]; then + echo "Specs not found!" + fi + + echo "spec=$spec" >> $GITHUB_ENV + - name: Transform Specs + working-directory: specs + run: npx --yes -p @expediagroup/spec-transformer cli -i ${{ env.spec }} -o ${{ env.spec }} -to + - name: Run Mock Server + working-directory: specs + run: java -jar specmatic.jar stub ${{ env.spec }} --port 8080 & disown + - name: Wait for Mock Server to Start + run: sleep 10 + - name: Verify Server is Running + run: | + status=$(curl --write-out '%{http_code}' --silent --output /dev/null http://localhost:8080/$(uuidgen)) + if [ $status -e 000 ]; then + echo "Server not running!" + exit 1 + fi + diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 000000000..b9daf8f42 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,9 @@ +on: push +jobs: + main: + uses: ./.github/workflows/selfserve-service-mock.yaml + with: + repository: ${{ github.repository }} + ref: "${{ github.head_ref || github.ref_name }}" + specs_path: 'release/rapid/src/specs.yaml' + diff --git a/sdk-test/src/main/kotlin/com/expediagroup/sdk/test/contract/extension/File.kt b/sdk-test/src/main/kotlin/com/expediagroup/sdk/test/contract/extension/File.kt index 41332b001..fee15a151 100644 --- a/sdk-test/src/main/kotlin/com/expediagroup/sdk/test/contract/extension/File.kt +++ b/sdk-test/src/main/kotlin/com/expediagroup/sdk/test/contract/extension/File.kt @@ -15,14 +15,8 @@ */ package com.expediagroup.sdk.test.contract.extension -import io.specmatic.conversions.EnvironmentAndPropertiesConfiguration import io.specmatic.conversions.OpenApiSpecification -import io.specmatic.core.Feature -import io.specmatic.core.Hook -import io.specmatic.core.OPENAPI_FILE_EXTENSIONS -import io.specmatic.core.PassThroughHook -import io.specmatic.core.SecurityConfiguration -import io.specmatic.core.unsupportedFileExtensionContractException +import io.specmatic.core.* import java.io.File /** @@ -34,7 +28,6 @@ import java.io.File * @param sourceRepositoryBranch optional branch of source repository. * @param specificationPath optional path to the specification file. * @param securityConfiguration optional security configuration. - * @param environmentAndPropertiesConfiguration configuration for environment and properties, default is EnvironmentAndPropertiesConfiguration. * @throws unsupportedFileExtensionContractException if the file extension is not supported. * @return converted Feature object. */ @@ -45,7 +38,7 @@ fun File.toSpecmaticFeature( sourceRepositoryBranch: String? = null, specificationPath: String? = null, securityConfiguration: SecurityConfiguration? = null, - environmentAndPropertiesConfiguration: EnvironmentAndPropertiesConfiguration = EnvironmentAndPropertiesConfiguration() + specmaticConfig: SpecmaticConfig = SpecmaticConfig() ): Feature = when (extension) { in OPENAPI_FILE_EXTENSIONS -> @@ -57,7 +50,7 @@ fun File.toSpecmaticFeature( sourceRepositoryBranch = sourceRepositoryBranch, specificationPath = specificationPath, securityConfiguration = securityConfiguration, - environmentAndPropertiesConfiguration = environmentAndPropertiesConfiguration + specmaticConfig = specmaticConfig ).toFeature() else -> throw unsupportedFileExtensionContractException(path, extension) diff --git a/sdk-test/src/main/resources/templates/expediagroup-sdk/main.mustache b/sdk-test/src/main/resources/templates/expediagroup-sdk/main.mustache index c8520bd6a..98f7216c3 100644 --- a/sdk-test/src/main/resources/templates/expediagroup-sdk/main.mustache +++ b/sdk-test/src/main/resources/templates/expediagroup-sdk/main.mustache @@ -27,4 +27,4 @@ class Main { } } } -} +} \ No newline at end of file diff --git a/sdk-test/src/main/resources/templates/expediagroup-sdk/pom.mustache b/sdk-test/src/main/resources/templates/expediagroup-sdk/pom.mustache index 6bec061b9..fa53e7dbc 100644 --- a/sdk-test/src/main/resources/templates/expediagroup-sdk/pom.mustache +++ b/sdk-test/src/main/resources/templates/expediagroup-sdk/pom.mustache @@ -7,6 +7,12 @@ Rapid Java SDK Tests Expedia Group Rapid Java SDK Tests + + org.springframework.boot + spring-boot-starter-parent + 3.3.3 + + 1.8 1.8 @@ -104,7 +110,8 @@ maven-compiler-plugin 3.8.1 - 1.8 + + 1.8 1.8