From ffb33a49e40e9dbd3f4daf57f4953a4068b8ffa0 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Fri, 14 Nov 2025 23:10:36 +0530 Subject: [PATCH] ISSUE-44: Hithomelabs/HomeLabDocker#44 Setting up workflow to run integration tests --- .gitea/workflows/integration_test.yaml | 26 +++++++++ .../application-integration.properties | 5 ++ .../CoudflareApiIntegrationTest.java | 53 +++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 .gitea/workflows/integration_test.yaml create mode 100644 src/main/resources/application-integration.properties create mode 100644 src/test/java/com/hithomelabs/CFTunnels/Integration/CoudflareApiIntegrationTest.java diff --git a/.gitea/workflows/integration_test.yaml b/.gitea/workflows/integration_test.yaml new file mode 100644 index 0000000..2a46a19 --- /dev/null +++ b/.gitea/workflows/integration_test.yaml @@ -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 test --tests "com.hithomelabs.CFTunnels.Integration.CoudflareApiIntegrationTest" \ No newline at end of file diff --git a/src/main/resources/application-integration.properties b/src/main/resources/application-integration.properties new file mode 100644 index 0000000..d2ec183 --- /dev/null +++ b/src/main/resources/application-integration.properties @@ -0,0 +1,5 @@ +cloudflare.accountId=${CLOUDFLARE_ACCOUNT_ID} +cloudflare.apiKey=${CLOUDFLARE_API_KEY} +cloudflare.email=${CLOUDFLARE_EMAIL} + +api.baseUrl \ No newline at end of file diff --git a/src/test/java/com/hithomelabs/CFTunnels/Integration/CoudflareApiIntegrationTest.java b/src/test/java/com/hithomelabs/CFTunnels/Integration/CoudflareApiIntegrationTest.java new file mode 100644 index 0000000..94c3076 --- /dev/null +++ b/src/test/java/com/hithomelabs/CFTunnels/Integration/CoudflareApiIntegrationTest.java @@ -0,0 +1,53 @@ +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.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") +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 httpEntity = new HttpEntity<>("", authKeyEmailHeader.getHttpHeaders()); + ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, Map.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + List> tunnelList = (List>) response.getBody().get("result"); + boolean hasName = tunnelList.stream() + .anyMatch(tunnel -> "devtunnel".equals(tunnel.get("name"))); + assertTrue(hasName); + } + +}