Merge pull request 'ISSUE-44: Adding integration tests and setting up workflow' (#88) from hitanshu/CFTunnels:ISSUE-44 into test
Reviewed-on: #88
This commit is contained in:
commit
7ff72fb489
26
.gitea/workflows/integration_test.yaml
Normal file
26
.gitea/workflows/integration_test.yaml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
name: Daily cloudflare API integration test
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ test ]
|
||||||
|
# schedule:
|
||||||
|
# - cron: '0 * * * *' # Every hour
|
||||||
|
# workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
cloudflare-api-test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: JDK setup
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: 'zulu'
|
||||||
|
java-version: '17'
|
||||||
|
- name: Run integration tests with Cloudflare API
|
||||||
|
env:
|
||||||
|
SPRING_PROFILES_ACTIVE: integration
|
||||||
|
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_KEY }}
|
||||||
|
CLOUDFLARE_EMAIL: hitanshu98@gmail.com
|
||||||
|
run: ./gradlew integrationTestOnly
|
||||||
11
build.gradle
11
build.gradle
@ -15,6 +15,17 @@ java {
|
|||||||
|
|
||||||
test {
|
test {
|
||||||
systemProperty 'spring.profiles.active', 'test'
|
systemProperty 'spring.profiles.active', 'test'
|
||||||
|
useJUnitPlatform {
|
||||||
|
excludeTags 'integration'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register('integrationTestOnly', Test) {
|
||||||
|
useJUnitPlatform {
|
||||||
|
includeTags 'integration'
|
||||||
|
}
|
||||||
|
description = 'Runs only integration tests tagged with @Tag("integration")'
|
||||||
|
group = 'verification'
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
rootProject.name = 'CFTunnels'
|
|
||||||
@ -5,10 +5,12 @@ import io.swagger.v3.oas.models.servers.Server;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@Profile("!integration")
|
||||||
public class OpenApiConfig {
|
public class OpenApiConfig {
|
||||||
|
|
||||||
@Value("${api.baseUrl}")
|
@Value("${api.baseUrl}")
|
||||||
|
|||||||
3
src/main/resources/application-integration.properties
Normal file
3
src/main/resources/application-integration.properties
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
cloudflare.accountId=${CLOUDFLARE_ACCOUNT_ID}
|
||||||
|
cloudflare.apiKey=${CLOUDFLARE_API_KEY}
|
||||||
|
cloudflare.email=${CLOUDFLARE_EMAIL}
|
||||||
@ -4,12 +4,6 @@ cloudflare.apiKey=${CLOUDFLARE_API_KEY}
|
|||||||
cloudflare.email=${CLOUDFLARE_EMAIL}
|
cloudflare.email=${CLOUDFLARE_EMAIL}
|
||||||
spring.profiles.active=${ENV}
|
spring.profiles.active=${ENV}
|
||||||
|
|
||||||
# set root level
|
|
||||||
logging.level.root=INFO
|
|
||||||
# package-specific
|
|
||||||
logging.level.org.springframework=TRACE
|
|
||||||
logging.level.com.myapp=INFO
|
|
||||||
|
|
||||||
/ * * Masking sure app works behind a reverse proxy
|
/ * * Masking sure app works behind a reverse proxy
|
||||||
server.forward-headers-strategy=framework
|
server.forward-headers-strategy=framework
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,55 @@
|
|||||||
|
package com.hithomelabs.CFTunnels.Integration;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.hithomelabs.CFTunnels.Config.CloudflareConfig;
|
||||||
|
import com.hithomelabs.CFTunnels.Headers.AuthKeyEmailHeader;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Tag;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
|
@ActiveProfiles("integration")
|
||||||
|
@Tag("integration")
|
||||||
|
public class CoudflareApiIntegrationTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
TestRestTemplate restTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
AuthKeyEmailHeader authKeyEmailHeader;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CloudflareConfig cloudflareConfig;
|
||||||
|
|
||||||
|
private static ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Calls cloudflare cfd tunnels API and checks that dev tunnel should be a part of the response")
|
||||||
|
public void getTunnelsTest(){
|
||||||
|
|
||||||
|
// * * Resource URL to hit get request at
|
||||||
|
String url = "https://api.cloudflare.com/client/v4/accounts/" + cloudflareConfig.getAccountId() + "/cfd_tunnel";
|
||||||
|
HttpEntity<String> httpEntity = new HttpEntity<>("", authKeyEmailHeader.getHttpHeaders());
|
||||||
|
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, Map.class);
|
||||||
|
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||||
|
List<Map<String, Object>> tunnelList = (List<Map<String, Object>>) response.getBody().get("result");
|
||||||
|
boolean hasName = tunnelList.stream()
|
||||||
|
.anyMatch(tunnel -> "devtunnel".equals(tunnel.get("name")));
|
||||||
|
assertTrue(hasName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user