pact-foundation / pact-net

.NET version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://pact.io
MIT License
848 stars 234 forks source link

DevContainer: Unable to load shared library 'pact_ffi' or one of its dependencies #500

Closed franvivas closed 6 months ago

franvivas commented 6 months ago

Previous issues

Version information: Do Not Work

Do Work

Describe the bug I work with devcontainer. If I use the devcontainer below i get this error:

System.DllNotFoundException : Unable to load shared library 'pact_ffi' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.19/pact_ffi.so: cannot open shared object file: No such file or directory

Stack Trace: at PactNet.Interop.NativeInterop.LogToBuffer(LevelFilter levelFilter) at PactNet.PactExtensions.InitialiseLogging(PactLogLevel level) at PactNet.PactExtensions.WithHttpInteractions(IPactV3 pact, Nullable1 port, IPAddress host) at PactNet.PactExtensions.UsingNativeBackend(IPactV3 pact, Nullable1 port, IPAddress host) at pact_test.xunit.tests.UnitTest1..ctor() in /workspaces/pact_ffi/pact-test.xunit.tests/UnitTest1.cs:line 13 at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)

Steps To Reproduce devcontainer.son

{
  "name": "My Test Dev Container",
  // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
  "dockerComposeFile": "docker-compose.yml",
  "service": "app",
  "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
  "features": {
    "ghcr.io/devcontainers/features/dotnet:2": {
      "version": "8.0",
      "additionalVersions": "7.0"
    },
    "ghcr.io/devcontainers/features/docker-in-docker:2": {}
  },
  "containerEnv": {},
  "customizations": {
    "vscode": {
      "extensions": [
        "ms-dotnettools.csdevkit",
        "fernandoescolar.vscode-solution-explorer"
      ]
    }
  }
}

docker-compose.yaml

version: "3.8"
services:
  app:
    image: mcr.microsoft.com/devcontainers/base:bullseye
    volumes:
      - ../..:/workspaces:cached
    command: sleep infinity
    networks:
      - pactnetwork

networks:
  pactnetwork:
namespace pact_test.xunit.tests;

using System.Net;
using PactNet;

public class UnitTest1
{
    private readonly IPactBuilderV3 _pactBuilder;

    public UnitTest1()
    {
        var pact = Pact.V3("Something API Consumer", "Something API");
        _pactBuilder = pact.UsingNativeBackend();
    }

    [Fact]
    public async Task Test()
    {
        // Arrange
        _pactBuilder
            .UponReceiving("a request")
                .WithRequest(HttpMethod.Get, "/")
            .WillRespond()
                .WithStatus(HttpStatusCode.OK);

        await _pactBuilder.VerifyAsync(async ctx =>
        {
            var client = new HttpClient { BaseAddress = ctx.MockServerUri };

            var response = await client.GetAsync("/");

            response.EnsureSuccessStatusCode();
        });
    }
}

Expected behavior Pass the test and create the pact file

Log Output Starting test execution, please wait... A total of 1 test files matched the specified pattern. [xUnit.net 00:00:00.29] pact_test.xunit.tests.UnitTest1.Test [FAIL] Failed pact_test.xunit.tests.UnitTest1.Test [1 ms] Error Message: System.DllNotFoundException : Unable to load shared library 'pact_ffi' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.19/pact_ffi.so: cannot open shared object file: No such file or directory /workspaces/pact_ffi/pact-test.xunit.tests/bin/Debug/net7.0/pact_ffi.so: cannot open shared object file: No such file or directory /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.19/libpact_ffi.so: cannot open shared object file: No such file or directory /workspaces/pact_ffi/pact-test.xunit.tests/bin/Debug/net7.0/libpact_ffi.so: cannot open shared object file: No such file or directory /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.19/pact_ffi: cannot open shared object file: No such file or directory /workspaces/pact_ffi/pact-test.xunit.tests/bin/Debug/net7.0/pact_ffi: cannot open shared object file: No such file or directory /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.19/libpact_ffi: cannot open shared object file: No such file or directory /workspaces/pact_ffi/pact-test.xunit.tests/bin/Debug/net7.0/libpact_ffi: cannot open shared object file: No such file or directory

Stack Trace: at PactNet.Interop.NativeInterop.LogToBuffer(LevelFilter levelFilter) at PactNet.PactExtensions.InitialiseLogging(PactLogLevel level) at PactNet.PactExtensions.WithHttpInteractions(IPactV3 pact, Nullable1 port, IPAddress host) at PactNet.PactExtensions.UsingNativeBackend(IPactV3 pact, Nullable1 port, IPAddress host) at pact_test.xunit.tests.UnitTest1..ctor() in /workspaces/pact_ffi/pact-test.xunit.tests/UnitTest1.cs:line 13 at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)

Failed! - Failed: 1, Passed: 0, Skipped: 0, Total: 1, Duration: < 1 ms - pact-test.xunit.tests.dll (net7.0)

Additional context If I launch this devcontainer in a Mac with Intel x64, it works. If I launch this devcontainer in a Mac with ARM M2, it does not work. If I launch this test locally in a Mac with ARM M2, it works.

adamrodger commented 6 months ago

Mac ARM isn't supported in 4.x. Support is added from 5.0.0-beta.2 onwards. See https://github.com/pact-foundation/pact-net/issues/451#issuecomment-1946712324