diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index 5e03fdca..ac0b9c2f 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -45,3 +45,57 @@ jobs: uses: codecov/codecov-action@v2 with: token: ${{ secrets.CODECOV_TOKEN }} + + + integration-test: + + strategy: + matrix: + os: + - ubuntu-latest + java-version: + - 11 + - 17 + - 21 + + runs-on: ${{ matrix.os }} + + steps: + + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v3 + with: + java-version: ${{ matrix.java-version }} + distribution: corretto + cache: maven + + - name: Bring up Skyramp worker + run: > + docker run + --detach + --restart always + -p8081:8081 + -p35142:35142 + --volume worker:/etc/skyramp + public.ecr.aws/j1n2c2p2/rampup/worker:latest + + - name: Install Skyramp + run: bash -c "$(curl -fsSL https://skyramp.dev/installer.sh)" + + - name: Apply Skyramp mock configurations + run: > + skyramp mocker apply + --address localhost:35142 + --path skyramp + mock-gh + + - name: Run integration tests + run: > + mvn + --batch-mode + --file pom.xml + -Dsytle.colors=always + --errors + -DskipUnitTests + verify diff --git a/pom.xml b/pom.xml index 86dd776b..1c2df7b1 100644 --- a/pom.xml +++ b/pom.xml @@ -387,6 +387,9 @@ org.apache.maven.plugins maven-surefire-plugin 3.2.1 + + ${skipUnitTests} + maven-jar-plugin diff --git a/skyramp/endpoints/endpoints-gh.yaml b/skyramp/endpoints/endpoints-gh.yaml new file mode 100644 index 00000000..38c36eee --- /dev/null +++ b/skyramp/endpoints/endpoints-gh.yaml @@ -0,0 +1,25 @@ +version: v1 +services: + - name: gh-mock + port: 8081 + alias: gh-mock + protocol: rest +endpoints: + - name: tag-endpoint + path: /repos/someowner/somerepo/git/refs/tags/0.0.1 + methods: + - name: method + type: GET + serviceName: gh-mock + - name: annotated-tag-endpoint + path: /repos/someowner/somerepo/git/tags/27210625b551200e7d3dc608935b1454523eaa8 + methods: + - name: method + type: GET + serviceName: gh-mock + - name: ref-list-endpoint + path: /repos/someowner/somerepo/git/matching-refs/heads/feature + methods: + - name: method + type: GET + serviceName: gh-mock diff --git a/skyramp/mocks/mock-gh.yaml b/skyramp/mocks/mock-gh.yaml new file mode 100644 index 00000000..9dd4e942 --- /dev/null +++ b/skyramp/mocks/mock-gh.yaml @@ -0,0 +1,7 @@ +version: v1 +mock: + description: gh-mock + responses: + - responseName: tag-response + - responseName: annotated-tag-response + - responseName: ref-list-response diff --git a/skyramp/responses/response-gh-annotated-tag.yaml b/skyramp/responses/response-gh-annotated-tag.yaml new file mode 100644 index 00000000..1b88fd35 --- /dev/null +++ b/skyramp/responses/response-gh-annotated-tag.yaml @@ -0,0 +1,29 @@ +version: v1 +responses: + - name: annotated-tag-response + blob: |- + { + "node_id": "MDM6VGFnODc0MTU6ODI3MjEwNjI1YjU1MTIwMGU3ZDNkYzYwODkzNWIxNDU0NTIzZWFhOA==", + "sha": "827210625b551200e7d3dc608935b1454523eaa8", + "url": "https://github.com/api/v3/repos/golden-path-wilson/data-gp-workshop-wilson/git/tags/827210625b551200e7d3dc608935b1454523eaa8", + "tagger": { + "name": "Tasnim Rahman", + "email": "tasnimr@spotify.com", + "date": "2018-12-28T21:44:33Z" + }, + "object": { + "sha": "ee959eb71f7041260dc864fb24574eec4caa8019", + "type": "commit", + "url": "https://github.com/api/v3/repos/golden-path-wilson/data-gp-workshop-wilson/git/commits/ee959eb71f7041260dc864fb24574eec4caa8019" + }, + "tag": "v7.0.0", + "message": "7.0.0\n", + "verification": { + "verified": false, + "reason": "unsigned", + "signature": null, + "payload": null + } + } + endpointName: annotated-tag-endpoint + methodName: method diff --git a/skyramp/responses/response-gh-ref-list.yaml b/skyramp/responses/response-gh-ref-list.yaml new file mode 100644 index 00000000..ce641ba1 --- /dev/null +++ b/skyramp/responses/response-gh-ref-list.yaml @@ -0,0 +1,28 @@ +version: v1 +responses: + - name: ref-list-response + blob: |- + [ + { + "ref": "refs/heads/feature-a", + "node_id": "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlLWE=", + "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/feature-a", + "object": { + "type": "commit", + "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd", + "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd" + } + }, + { + "ref": "refs/heads/feature-b", + "node_id": "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlLWI=", + "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/feature-b", + "object": { + "type": "commit", + "sha": "612077ae6dffb4d2fbd8ce0cccaa58893b07b5ac", + "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/612077ae6dffb4d2fbd8ce0cccaa58893b07b5ac" + } + } + ] + endpointName: ref-list-endpoint + methodName: method diff --git a/skyramp/responses/response-gh-tag.yaml b/skyramp/responses/response-gh-tag.yaml new file mode 100644 index 00000000..b3c2b7a6 --- /dev/null +++ b/skyramp/responses/response-gh-tag.yaml @@ -0,0 +1,15 @@ +version: v1 +responses: + - name: tag-response + blob: |- + { + "ref": "refs/tags/0.0.1", + "url": "https://github.com/api/v3/repos/someorg/somerepo/git/refs/tags/0.0.1", + "object": { + "sha": "5926dd300de5fee31d445c57be223f00e128a634", + "type": "commit", + "url": "https://github.com/api/v3/repos/someorg/somerepo/git/commits/5926dd300de5fee31d445c57be223f00e128a634" + } + } + endpointName: tag-endpoint + methodName: method diff --git a/src/test/java/com/spotify/github/v3/clients/GitDataClientIT.java b/src/test/java/com/spotify/github/v3/clients/GitDataClientIT.java new file mode 100644 index 00000000..882dbd55 --- /dev/null +++ b/src/test/java/com/spotify/github/v3/clients/GitDataClientIT.java @@ -0,0 +1,71 @@ +/*- + * -\-\- + * github-api + * -- + * Copyright (C) 2016 - 2023 Spotify AB + * -- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * -/-/- + */ + +package com.spotify.github.v3.clients; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.StringContains.containsString; + +import com.spotify.github.v3.git.Reference; +import com.spotify.github.v3.git.Tag; +import java.net.URI; +import java.util.List; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class GitDataClientIT { + + private static final URI URL_TO_MOCK = URI.create("http://localhost:8081"); + + private static GitHubClient github; + private static GitDataClient gitDataClient; + + @BeforeAll + static void beforeAll() { + // URL points to mock which is set up with Skyramp + // Mock config can be found in dir `skyramp/` + github = GitHubClient.create(URL_TO_MOCK, "TOKEN"); + gitDataClient = GitDataClient.create(github, "someowner", "somerepo"); + } + + @Test + public void getTagRef() throws Exception { + final Reference reference = gitDataClient.getTagReference("0.0.1").get(); + assertThat(reference.object().sha(), is("5926dd300de5fee31d445c57be223f00e128a634")); + } + + @Test + public void getTag() throws Exception { + final Tag tag = gitDataClient.getTag("27210625b551200e7d3dc608935b1454523eaa8").get(); + assertThat(tag.object().sha(), is("ee959eb71f7041260dc864fb24574eec4caa8019")); + assertThat(tag.object().type(), is("commit")); + } + + @Test + public void listMatchingReferences() throws Exception { + final List matchingReferences = + gitDataClient.listMatchingReferences("heads/feature").get(); + assertThat(matchingReferences.size(), is(2)); + for (Reference ref : matchingReferences) { + assertThat(ref.ref(), containsString("heads/feature")); + } + } +}