Skip to content

Commit

Permalink
feat: enable integration testing with Skyramp Mocker
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-seifert committed Dec 7, 2023
1 parent 90adff7 commit 363a122
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 0 deletions.
25 changes: 25 additions & 0 deletions skyramp/endpoints/endpoints-gh-mock.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-mock.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-mock-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-mock-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-mock-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
69 changes: 69 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,69 @@
/*-
* -\-\-
* 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() {
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"));
}
}
}

0 comments on commit 363a122

Please sign in to comment.