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

Add protodefinition and refer it from mapping #1249

Closed
GomesNayagam opened this issue Jan 29, 2025 · 7 comments
Closed

Add protodefinition and refer it from mapping #1249

GomesNayagam opened this issue Jan 29, 2025 · 7 comments
Assignees
Labels

Comments

@GomesNayagam
Copy link

Feature Request

I am planning to use grpc mock using docker container via WireMockContainerBuilder() like standalone WIreMock.Start() server. While doing that i noticed i am missing .AddProtoDefinition(id, protoDefinitionText) signatue for Container way.

Describe the solution you'd like
Prefer to as close as possible like

var server = WireMockServer.Start() 
server.AddProtoDefinition(id, protoDefinitionText)

var wireMockContainer = new WireMockContainerBuilder()
    .WithAutoRemove(true)
    .WithCleanUp(true)
   // .WithBindMount(TestHelper.GetAbsolutePath(@"mocks\greet"), "/home/wiremock")
   // .AddProtoDefinition(id, protoDefinitionText)
    .WithCommand("--UseHttp2")
    .AddUrl("grpc://*:9090")
    .AddUrl("http://*:8080")
    .Build();

Describe alternatives you've considered

  var result = await httpClient.PostAsync("/__admin/mappings", new StringContent(mappingsJson, Encoding.UTF8, "application/json"));
  result.EnsureSuccessStatusCode();

Is your feature request supported by WireMock (java version)? Please provide details.
Verified with WireMock.Net author and it is possible to include this feature.

Additional context
More discussion here
#1239

@StefH
Copy link
Collaborator

StefH commented Feb 7, 2025

#1250

@StefH
Copy link
Collaborator

StefH commented Feb 8, 2025

@GomesNayagam

A new preview version from WireMock.Net + Docker container is created: 1.7.2-preview-01

This example should work now:

var wireMockContainer = new WireMockContainerBuilder()
    .WithAutoRemove(true)
    .WithCleanUp(true)
    .AddUrl("grpc://*:9090")
    .AddProtoDefinition("my-greeter", ReadFile("greet.proto"))
    .Build();

@GomesNayagam
Copy link
Author

GomesNayagam commented Feb 11, 2025

@StefH it throws method not allowed error:

Code used using these files
a) https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/__admin/mappings/protobuf-mapping-3.json
b)https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/Grpc/greet.proto

            var protoDefinition = File.ReadAllText(
             TestHelper.GetAbsolutePath("Grpc") + @"\greet.proto"
             );

            var wireMockContainer = new WireMockContainerBuilder()
                .WithAutoRemove(true)
                .WithCleanUp(true)
                .WithCommand("--UseHttp2")
                .AddUrl("grpc://*:9090")
                .AddUrl("http://*:8080")
                .AddProtoDefinition("my-greeter", protoDefinition)
                .Build();

            await wireMockContainer.StartAsync();

            var mappingsJson = File.ReadAllText(
                TestHelper.GetAbsolutePath(@"mocks\greet") + @"\hellorequest.json"
            );

            var address = wireMockContainer.GetPublicUrls()[9090];
            var address2 = wireMockContainer.GetPublicUrls()[8080];

            using var httpClient = wireMockContainer.CreateClient();

            var result = await httpClient.PostAsync("/__admin/mappings", new StringContent(mappingsJson, Encoding.UTF8, "application/json"));
            result.EnsureSuccessStatusCode();

            var channel = GrpcChannel.ForAddress(address);

            var client = new Greeter.GreeterClient(channel);

            var res = await client.SayHelloAsync(new HelloRequest { Name = "stef" });

@StefH
Copy link
Collaborator

StefH commented Feb 11, 2025

Are you sure you have the correct docker container version?
Best is to delete all local docker containers for WireMock.Net Linux / Alpine Linux and then try again.

BTW I used protobug-mapping-4 as test.
See
https://github.com/WireMock-Net/WireMock.Net/pull/1250/files

@GomesNayagam
Copy link
Author

thats the good point let me delete the image and retry and let u know

@GomesNayagam
Copy link
Author

GomesNayagam commented Feb 11, 2025

apologies for my silly mistake, it works. great work once again. @StefH pls tag me when it is publicly available.

hope u tag new version for those docker image as well besides client version.

@StefH StefH closed this as completed Feb 12, 2025
@StefH
Copy link
Collaborator

StefH commented Feb 12, 2025

  • new NuGet 1.7.2 will be released within the hour
  • docker images later today
  • all docker images are tagged 1.7.2 and latest, however I still think you need delete your local latest to get the real latest version, I need to think on that how the dependency between the NuGet and Docker version can be defined / enforced.....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants