首页 > 解决方案 > 针对已部署的 HTTPS 提供程序运行 Pact 提供程序测试

问题描述

我想为我的客户和 API 设置 Pact 合同测试。我的 API 无法在本地运行,因此我希望能够在部署到生产环境之前针对已部署的 API 暂存版本运行提供程序测试。

我在网上看到的大多数提供者测试示例都使用了 localhost。尝试针对我部署的 HTTPS 端点运行提供程序测试时,测试失败并显示read server hello A: unknown protocol. 是不支持 HTTPS 协议,还是我遗漏了什么?

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))},
    })
}

使用pact-provider-verifier命令行工具可以正常工作。

标签: pactpact-go

解决方案


它应该支持通过 HTTPS 进行验证,但目前我不认为我们在 Pact Go 中轻松支持带有自签名证书的 SSL(请参阅https://github.com/pact-foundation/pact-go/issues/66)。

理论上,您应该能够为您的 SSL 配置 [1] 设置一个环境变量,如下所示:

要连接到使用自定义 SSL 证书的 Pact Broker,请将环境变量 $SSL_CERT_FILE 或 $SSL_CERT_DIR 设置为包含相应证书的路径。


推荐阅读