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

SWATCH-1969: Generate an export service client from the openapi spec #2932

Merged
merged 2 commits into from
Jan 10, 2024

Conversation

Sgitario
Copy link
Contributor

@Sgitario Sgitario commented Jan 8, 2024

Jira issue: SWATCH-1969

Description

In order for swatch to communicate with the export-service, we want to use their openapi spec to generate swatch client code - like we do with other external services (subscription, entitlement gateway, product service, etc.)

Spec: https://raw.githubusercontent.com/RedHatInsights/export-service-go/main/static/spec/private.yaml

In addition to the client, I also added a stub version of the client.

Testing

Added integration tests with Wiremock to ensure the communication is working fine. Further testing must be done when using the client in our export service.

Test with export service locally:
1.- Clone the repository:

git clone https://github.com/RedHatInsights/export-service-go

2.- Start the export service:

cd export-service-go
make run

3.- Create a dummy export request:

make sample-request-create-export

4.- Copy this file to clients/export-client/src/test/resources.

5.- Add the following test case in ExportApiClientFactoryTest:

@Test
  void testDownloadExportUploadLocally() throws Exception {
    config.setUrl("http://localhost:10010");
    // values taken from https://github.com/RedHatInsights/export-service-go/blob/48077b1a04e025f2282f924d98846c7bafc8796d/Makefile#L81
    config.setPsk("testing-a-psk");
    ExportApiClientFactory factory = new ExportApiClientFactory(config);
    ExportApi client = factory.getObject();
    String body = new String(ExportApiClientFactoryTest.class
            .getResourceAsStream("/example_export_upload.json").readAllBytes());
    // values taken from new export CURL step
    UUID exportId = UUID.fromString(<Use EXPORT_ID value from step 3>);
    String applicationName = "exampleApplication";
    UUID resource = UUID.fromString(<Use RESOURCE value from step 3>);
    client.downloadExportUpload(exportId, applicationName, resource, body);
  }

6.- Run the test and you should see the following trace in the export service (from step 2):

2024-01-09T08:53:09.4844Z	info	logger/logger.go:94		{"protocol": "HTTP/1.1", "request": "POST", "path": "/app/export/v1/0ff33f9c-f0ce-4771-8781-8e02886fe931/exampleApplication/fd96af36-f5d2-464a-ab21-1a0114c445cc/upload", "latency": 0.026452057, "status": 202, "size": 17, "request_id": "localhost.localdomain/OJNk12J9HU-000004"}

@Sgitario Sgitario added the QE Unneeded Pull request does not need QE approval label Jan 8, 2024
@lindseyburnett
Copy link
Contributor

Used different test steps because I wanted to test with EE and because my IDE was having classloader issues with the example json. Used a slightly different unit test though that the export-service is getting hit and is responding because I'm expecting a 404 error response (since I didn't initiate an export request from the export service first)

  1. Deploy with bonfire

  2. Port forward the export-service pod
    oc port-forward Service/export-service-service 8000

  3. Apply unit test patch and verify export-service in EE pod responded.

patch: swatch-1969-unit-test.txt

git apply swatch-1969-unit-test.txt

./gradlew :clients:export-client:test --tests '*.testDownloadExportUploadLocally'

@lindseyburnett lindseyburnett merged commit 12770ca into main Jan 10, 2024
5 checks passed
@lindseyburnett lindseyburnett deleted the jcarvaja/SWATCH-1969 branch January 10, 2024 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QE Unneeded Pull request does not need QE approval
Projects
None yet
2 participants