Running Pact provider tests against deployed HTTPS provider

1k views Asked by At

I want to set up Pact contract testing for my clients and APIs. My APIs cannot be run locally, so I want to be able to run provider tests against deployed staging version of the API before deploying to production.

Most examples I've seen online of provider tests have used localhost. When trying to run a provider test against my deployed HTTPS endpoint, the test fails with read server hello A: unknown protocol. Is the HTTPS protocol not supported, or am I missing something?

func TestTenantProvider(t *testing.T) {

    // Create Pact connecting to local Daemon
    pact := &dsl.Pact{
        Consumer: "TenantConsumer",
        Provider: "TenantProvider",
    }


    // Verify the Provider with local Pact Files
    pact.VerifyProvider(t, types.VerifyRequest{
        ProviderBaseURL:        "https://my-staging-endpoint.com",
        PactURLs:               []string{filepath.ToSlash(fmt.Sprintf("%s/tenantconsumer-tenantprovider.json", pactDir))},
    })
}

Using the pact-provider-verifier cmd line tool works fine.

1

There are 1 answers

0
Matthew Fellows On

It should support verification over HTTPS, but currently I don't believe we support SSL with self-signed certificates easily in Pact Go (see https://github.com/pact-foundation/pact-go/issues/66).

In theory, you should be able to set an environment variable to your SSL configuration [1] as per below:

To connect to a Pact Broker that uses custom SSL cerificates, set the environment variable $SSL_CERT_FILE or $SSL_CERT_DIR to a path that contains the appropriate certificate.