wiremock/wiremock-testcontainers-java

Idea: Unify methods to get endpoint url

开放

#33 创建于 2023年5月2日

 (1 条评论) (1 个反应) (0 位负责人)Java (13 个派生)auto 404
enhancementhelp wantedtestcontainers

仓库指标

星标
 (66 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

Proposal

Goal is to simplify public interface of the WireMockContainer class

Current methods

public String getEndpoint() {
  return String.format("http://%s:%d", getHost(), getMappedPort(PORT));
}
public URI getRequestURI(String relativePath) throws URISyntaxException {
  return new URI(getEndpoint() + "/" + relativePath);
}

Option 1

Align method names with WireMockServer class

public String baseUrl() {
  return String.format("http://%s:%d", getHost(), getMappedPort(PORT));
}
public String url(String path) {
  if (!path.startsWith("/")) {
    path = "/" + path;
  }
  return baseUrl() + path;
}

Motivation

  1. Simplify switch from Embedded wiremock to Testcontainer
  2. Familiar api for developers

Option 2

  public String getEndpoint() {
    return String.format("http://%s:%d", getHost(), getMappedPort(PORT));
  }
  public String getEndpoint(String path) {
    if (!path.startsWith("/")) {
      path = "/" + path;
    }
    return getEndpoint() + path
  }

Motivation

  1. Use Overloaded methods getEndpoint
    • naming consistency
    • easier for developer to memorize and intuitively understand what method does
  2. Allow path to be with / and without it
  • simplify switch from WireMockServer to WireMockTestcontainer

References

No response

贡献者指南