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

Inject informative field names into C Structures #10

Open
oleg-nenashev opened this issue Sep 23, 2023 · 0 comments
Open

Inject informative field names into C Structures #10

oleg-nenashev opened this issue Sep 23, 2023 · 0 comments
Labels
breaking documentation Improvements or additions to documentation enhancement New feature or request

Comments

@oleg-nenashev
Copy link
Collaborator

oleg-nenashev commented Sep 23, 2023

When using CGO, structures like this one are generated:

/* Return type for RunContainer */
struct RunContainer_return {
	GoInt r0; /* id */
	char* r1; /* errstr */
};
extern struct RunContainer_return RunContainer(GoInt requestID);

/* Return type for GetURI */
struct GetURI_return {
	GoString r0; /* uri */
	GoInterface r1; /* e */
};

Maybe CGO could be tweaked or configured to inject proper field names to improve DevX

Wishlist

This is how we want to see the code once everything is done, maybe:

#include <stdio.h>
#include <string.h>
#include "testcontainers-c.h"
#include "testcontainers-c-wiremock.h"

#define DEFAULT_IMAGE "wiremock/wiremock:3.1.0-1"

int main() {
    printf("Using WireMock with the Testcontainers C binding:\n");

    printf("Creating new container: %s\n", DEFAULT_IMAGE);
    int requestId = NewContainerRequest(DEFAULT_IMAGE);
    WithExposedTcpPort(requestId, 8080);
    WithWaitForHttp(requestId, 8080, "/__admin/mappings");
    WithFile(requestId, "test_data/hello.json", "/home/wiremock/mappings/hello.json");
    struct TestContainer container = RunContainer(requestId);
    if (container.Id == -1) {
        printf("Failed to run the container: %s\n", container.errorMsg);
        return -1;
    }

    printf("Sending HTTP request to the container\n");
    struct HttpGetResponse response = SendHttpGet(container.Id, 8080, "/hello");
    if (response.code == -1) {
        printf("Failed to send HTTP request: %s\n", response.errorMsg);
        return -1;
    }
    if (response.code != 200) {
        printf("Request failed: HTTP-%d\n%s\n", response.code, response.errorMsg);
        return -1;
    }
    printf("Server Response: HTTP-%d\n%s\n\n", response.code, response.msg);
    return 0;
}
@oleg-nenashev oleg-nenashev added enhancement New feature or request breaking labels Sep 23, 2023
@oleg-nenashev oleg-nenashev changed the title Inject informative field name to C Structures Inject informative field name into C Structures Sep 23, 2023
@oleg-nenashev oleg-nenashev added the documentation Improvements or additions to documentation label Sep 23, 2023
@oleg-nenashev oleg-nenashev changed the title Inject informative field name into C Structures Inject informative field names into C Structures Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant