Skip to content

Commit

Permalink
fix(web): fix the mismatch in return types of EchoService.postEvent a…
Browse files Browse the repository at this point in the history
…pi stub and the actual api from echo (#1885) (#1886)

* test(web): add a test to demonstrate the mismatch in return types of EchoService.postEvent api stub and the actual api from echo.

* fix(web): fix the mismatch in return types of EchoService.postEvent api stub and the actual api from echo.

(cherry picked from commit ed77027)

Co-authored-by: Kiran Godishala <[email protected]>
  • Loading branch information
mergify[bot] and kirangodishala authored Mar 3, 2025
1 parent de72fa6 commit 826286d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Call<Map> webhooks(
Call<List<Map<String, String>>> getPubsubSubscriptions();

@POST("/")
Call<String> postEvent(@Body Map event);
Call<Void> postEvent(@Body Map event);

@GET("/quietPeriod")
Call<Map> getQuietPeriodState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
Expand Down Expand Up @@ -58,6 +59,7 @@
@TestPropertySource(
properties = {
"spring.config.location=classpath:gate-test.yml",
"services.echo.enabled=true",
"services.front50.applicationRefreshInitialDelayMs=3600000"
})
public class PipelineServiceTest {
Expand All @@ -67,6 +69,10 @@ public class PipelineServiceTest {
static WireMockExtension wmOrca =
WireMockExtension.newInstance().options(wireMockConfig().dynamicPort()).build();

@RegisterExtension
static WireMockExtension wmEcho =
WireMockExtension.newInstance().options(wireMockConfig().dynamicPort()).build();

@Autowired private WebApplicationContext webApplicationContext;

ObjectMapper objectMapper = new ObjectMapper();
Expand All @@ -90,6 +96,8 @@ public class PipelineServiceTest {
/** To prevent periodic calls to load accounts from clouddriver */
@MockBean DefaultProviderLookupService defaultProviderLookupService;

private static final String APPLICATION_NAME = "my-application";
private static final String PIPELINE_NAME = "my-pipeline-name";
private static final String USERNAME = "some user";
private static final String ACCOUNT = "my-account";
private static final String PIPELINE_EXECUTION_ID = "my-pipeline-execution-id";
Expand All @@ -99,6 +107,8 @@ static void registerUrls(DynamicPropertyRegistry registry) {
// Configure wiremock's random ports into gate
System.out.println("wiremock orca url: " + wmOrca.baseUrl());
registry.add("services.orca.base-url", wmOrca::baseUrl);
System.out.println("wiremock echo url: " + wmEcho.baseUrl());
registry.add("services.echo.base-url", wmEcho::baseUrl);
}

@BeforeEach
Expand Down Expand Up @@ -143,4 +153,21 @@ void invokeDeletePipelineExecution() throws Exception {
.andDo(print())
.andExpect(status().is2xxSuccessful());
}

@Test
void invokePipelineConfigViaEcho() throws Exception {
wmEcho.stubFor(WireMock.post(urlEqualTo("/")).willReturn(aResponse().withStatus(200)));

webAppMockMvc
.perform(
post("/pipelines/v2/" + APPLICATION_NAME + "/" + PIPELINE_NAME)
.header(
USER.getHeader(),
USERNAME) // to silence warning when X-SPINNAKER-USER is missing
.header(
ACCOUNTS.getHeader(),
ACCOUNT)) // to silence warning when X-SPINNAKER-ACCOUNTS is missing
.andDo(print())
.andExpect(status().is2xxSuccessful());
}
}

0 comments on commit 826286d

Please sign in to comment.