pact - 针对已部署的 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命令行工具可以正常工作。
解决方案
它应该支持通过 HTTPS 进行验证,但目前我不认为我们在 Pact Go 中轻松支持带有自签名证书的 SSL(请参阅https://github.com/pact-foundation/pact-go/issues/66)。
理论上,您应该能够为您的 SSL 配置 [1] 设置一个环境变量,如下所示:
要连接到使用自定义 SSL 证书的 Pact Broker,请将环境变量 $SSL_CERT_FILE 或 $SSL_CERT_DIR 设置为包含相应证书的路径。
推荐阅读
- laravel - 将多态模型传递给 Laravel 工匠命令构造
- c# - 带有字典键的动态 Linq
- java - 按钮背景的延迟加载
- shell - Gradle:无法使用 shell 命令初始化变量
- c# - Linq to SQL 属性映射到表
- plotly - 覆盖默认事件处理程序行为的正确方法是什么(例如,单击时切换跟踪可见性)?
- python - 字符串连接/索引给出 IndexError
- spring - 具有 OAuth2-ResourceServer 的 Spring 微服务仅返回 String 作为主体而不是我的自定义用户
- java - Apache POI 不更新值
- html - 样式降价的最佳方式