Integration test with Wiremock on Gitlab CI #451

Closed
opened 2025-12-29 15:24:07 +01:00 by adam · 2 comments
Owner

Originally created by @t0mmili on GitHub (Sep 22, 2022).

Hi, I was recently refactoring integration tests, which are currently running as a single docker-compose in the following way:

  • 1st service: localstack image - for running S3, DynamoDB locally.
  • 2nd service: terraform image - for creating S3 bucket and DynamoDB table.
  • 3rd service: dotnet image - for testing application with Wiremock as a mock server.

Everything is running just fine. But this solution is far from optimal in Gitlab CI, hence refactoring.

In Gitlab CI pipeline it looks like this so far:

  • dotnet (with terraform) as a main image
  • localstack as a service image

Terraform part is ok, but then it comes to integration tests and I get this error:

  Failed GetUserAttribute_ShouldReturnAttributeFromDynamoDb [34 s]
  Error Message:
   Expected response.StatusCode to be OK, but found InternalServerError.
  Stack Trace:
     at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message)
   at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
   at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
   at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
   at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
   at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
   at FluentAssertions.Primitives.ObjectAssertions.Be(Object expected, String because, Object[] becauseArgs)
   at MyAppApi.IntegrationTests.Controllers.UserAttributeControllerIntegrationTests.GetUserAttribute_ShouldReturnAttributeFromDynamoDb() in /builds/t0mmili/myapp/MyAppApi.IntegrationTests/Controllers/UserAttributeControllerIntegrationTests.cs:line 384
   at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
   at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter)
   at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke)
   at NUnit.Framework.Internal.Commands.TestMethodCommand.RunTestMethod(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.TestMethodCommand.Execute(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.<Execute>b__0()
   at NUnit.Framework.Internal.Commands.DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)

Wiremock settings:

A total of 1 test files matched the specified pattern.
09/22/2022 06:05:44 [Info] : By Stef Heyenrath (https://github.com/WireMock-Net/WireMock.Net)
09/22/2022 06:05:44 [Debug] : Server settings {
  "Port": null,
  "UseSSL": false,
  "StartAdminInterface": null,
  "ReadStaticMappings": null,
  "WatchStaticMappings": null,
  "WatchStaticMappingsInSubdirectories": null,
  "ProxyAndRecordSettings": null,
  "Urls": null,
  "StartTimeout": 100,
  "AllowPartialMapping": null,
  "AdminUsername": null,
  "AdminPassword": null,
  "AdminAzureADTenant": null,
  "AdminAzureADAudience": null,
  "RequestLogExpirationDuration": null,
  "MaxRequestLogCount": null,
  "CorsPolicyOptions": null,
  "AllowCSharpCodeMatcher": null,
  "AllowBodyForAllHttpMethods": null,
  "AllowOnlyDefinedHttpStatusCodeInResponse": null,
  "DisableJsonBodyParsing": null,
  "DisableRequestBodyDecompressing": null,
  "HandleRequestsSynchronously": null,
  "ThrowExceptionWhenMatcherFails": null,
  "CertificateSettings": null,
  "CustomCertificateDefined": false,
  "WebhookSettings": null,
  "UseRegexExtended": true,
  "SaveUnmatchedRequests": null
}
09/22/2022 06:05:44 [Info] : Server using .NET 6.0

I'm was trying to separate this error and it looks like it comes from Wiremock test server.
I also setup WireMockConsoleLogger, but all information I've got are above...
So my question is, how can I pull more details regarding this error? Or is it maybe obvious what is wrong and I just don't see it?

Originally created by @t0mmili on GitHub (Sep 22, 2022). Hi, I was recently refactoring integration tests, which are currently running as a single docker-compose in the following way: * 1st service: localstack image - for running S3, DynamoDB locally. * 2nd service: terraform image - for creating S3 bucket and DynamoDB table. * 3rd service: dotnet image - for testing application with Wiremock as a mock server. Everything is running just fine. But this solution is far from optimal in Gitlab CI, hence refactoring. In Gitlab CI pipeline it looks like this so far: * dotnet (with terraform) as a main image * localstack as a service image Terraform part is ok, but then it comes to integration tests and I get this error: ``` Failed GetUserAttribute_ShouldReturnAttributeFromDynamoDb [34 s] Error Message: Expected response.StatusCode to be OK, but found InternalServerError. Stack Trace: at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message) at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message) at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message) at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc) at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc) at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args) at FluentAssertions.Primitives.ObjectAssertions.Be(Object expected, String because, Object[] becauseArgs) at MyAppApi.IntegrationTests.Controllers.UserAttributeControllerIntegrationTests.GetUserAttribute_ShouldReturnAttributeFromDynamoDb() in /builds/t0mmili/myapp/MyAppApi.IntegrationTests/Controllers/UserAttributeControllerIntegrationTests.cs:line 384 at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted() at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter) at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke) at NUnit.Framework.Internal.Commands.TestMethodCommand.RunTestMethod(TestExecutionContext context) at NUnit.Framework.Internal.Commands.TestMethodCommand.Execute(TestExecutionContext context) at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.<Execute>b__0() at NUnit.Framework.Internal.Commands.DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action) ``` Wiremock settings: ``` A total of 1 test files matched the specified pattern. 09/22/2022 06:05:44 [Info] : By Stef Heyenrath (https://github.com/WireMock-Net/WireMock.Net) 09/22/2022 06:05:44 [Debug] : Server settings { "Port": null, "UseSSL": false, "StartAdminInterface": null, "ReadStaticMappings": null, "WatchStaticMappings": null, "WatchStaticMappingsInSubdirectories": null, "ProxyAndRecordSettings": null, "Urls": null, "StartTimeout": 100, "AllowPartialMapping": null, "AdminUsername": null, "AdminPassword": null, "AdminAzureADTenant": null, "AdminAzureADAudience": null, "RequestLogExpirationDuration": null, "MaxRequestLogCount": null, "CorsPolicyOptions": null, "AllowCSharpCodeMatcher": null, "AllowBodyForAllHttpMethods": null, "AllowOnlyDefinedHttpStatusCodeInResponse": null, "DisableJsonBodyParsing": null, "DisableRequestBodyDecompressing": null, "HandleRequestsSynchronously": null, "ThrowExceptionWhenMatcherFails": null, "CertificateSettings": null, "CustomCertificateDefined": false, "WebhookSettings": null, "UseRegexExtended": true, "SaveUnmatchedRequests": null } 09/22/2022 06:05:44 [Info] : Server using .NET 6.0 ``` I'm was trying to separate this error and it looks like it comes from Wiremock test server. I also setup WireMockConsoleLogger, but all information I've got are above... So my question is, how can I pull more details regarding this error? Or is it maybe obvious what is wrong and I just don't see it?
adam added the question label 2025-12-29 15:24:07 +01:00
adam closed this issue 2025-12-29 15:24:07 +01:00
Author
Owner

@StefH commented on GitHub (Sep 22, 2022):

You can call the /requests endpoint from the wiremock Docker to get more details.

https://github.com/WireMock-Net/WireMock.Net/wiki/Admin-API-Reference#__adminrequests

Btw normally when WireMock docker throws an exception, this will be logged in the console log?

Are you sure that WireMock throws exception?

@StefH commented on GitHub (Sep 22, 2022): You can call the /requests endpoint from the wiremock Docker to get more details. https://github.com/WireMock-Net/WireMock.Net/wiki/Admin-API-Reference#__adminrequests Btw normally when WireMock docker throws an exception, this will be logged in the console log? Are you sure that WireMock throws exception?
Author
Owner

@t0mmili commented on GitHub (Sep 26, 2022):

Thanks, it turned out it wasn't issue with WireMock, but rather with Localstack. I have extended WireMock server configure service method with some additional logging and got my answer. I was missing AWS_REGION env variable in pipeline configuration :) Which was obviously set in previous setup, before I switched to Gitlab CI, but during the migration I was copying example code from Localstack docs and they only had AWS_DEFAULT_REGION. Case closed!

@t0mmili commented on GitHub (Sep 26, 2022): Thanks, it turned out it wasn't issue with WireMock, but rather with Localstack. I have extended WireMock server configure service method with some additional logging and got my answer. I was missing AWS_REGION env variable in pipeline configuration :) Which was obviously set in previous setup, before I switched to Gitlab CI, but during the migration I was copying example code from Localstack docs and they only had AWS_DEFAULT_REGION. Case closed!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#451