WebTestClient 使用 E2E 测试获取 502 Bad gateway

我有一个阶段在 Jenkins 上运行 E2E 测试 我的测试看起来像下面这样:

@WebFluxTest(controllers = DHController.class)
public class E2ETest{

@BeforeEach
public void before(){
    RestAssured.baseURI = System.getProperty("EndPoint");
}

@Test
public void getWelcome() throws Exception {

    WebTestClient.bindToServer().baseUrl(baseURI).build().get()
            .uri("/dh/account")
            .exchange()
            .expectStatus().isOk();

 }
}

控制器类大致如下:

@RestController
@RequestMapping("/dh/account")
public class DHController {

@GetMapping()
public Mono<String> printDH() {
    logger.info("打印欢迎消息");
    return Mono.just("欢迎使用 DH 账户服务。");
  }
}

Jenkins 输出如下

  GET https://domain.name/dh/account
  > WebTestClient-Request-Id: [1]

  无内容

  < 502 BAD_GATEWAY Bad Gateway

  <html>
  <head><title>502 Bad Gateway</title></head>
  <body>
  <center><h1>502 Bad Gateway</h1></center>
  <hr><center>openresty/1.15.8.2</center>
  </body>
 </html>

执行测试 getWelcome() [com.dh.E2ETest] 的结果:失败

E2ETest > getWelcome() FAILED
  java.lang.AssertionError: 预期状态是:<200 OK>,但实际上是:<502 BAD_GATEWAY>

原文链接 https://stackoverflow.com/questions/70767873

点赞