Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration testing #160

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<skipTests>${skipUnitTests}</skipTests>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
25 changes: 25 additions & 0 deletions skyramp/endpoints/endpoints-gh.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions skyramp/mocks/mock-gh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: v1
mock:
description: gh-mock
responses:
- responseName: tag-response
- responseName: annotated-tag-response
- responseName: ref-list-response
29 changes: 29 additions & 0 deletions skyramp/responses/response-gh-annotated-tag.yaml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions skyramp/responses/response-gh-ref-list.yaml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions skyramp/responses/response-gh-tag.yaml
Original file line number Diff line number Diff line change
@@ -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
71 changes: 71 additions & 0 deletions src/test/java/com/spotify/github/v3/clients/GitDataClientIT.java
Original file line number Diff line number Diff line change
@@ -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<Reference> matchingReferences =
gitDataClient.listMatchingReferences("heads/feature").get();
assertThat(matchingReferences.size(), is(2));
for (Reference ref : matchingReferences) {
assertThat(ref.ref(), containsString("heads/feature"));
}
}
}
Loading