-
Notifications
You must be signed in to change notification settings - Fork 741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(web): fix the mismatches in the return types of APIs in gate and orca #1883
Merged
mergify
merged 5 commits into
spinnaker:master
from
kirangodishala:fix-delete-pipline-execution-error
Mar 1, 2025
+158
−12
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a9d3d1b
test(web): add a test to demonstrate the mismatch in api response typ…
kirangodishala 174297e
fix(web): fix the mismatches in the return types of apis in gate and …
kirangodishala dbf0d4a
refactor(web/test): mock DefaultProviderLookupService in PipelineServ…
dbyron-sf 3f9df52
refactor(web/test): remove request id header from PipelineServiceTest
dbyron-sf 073d67a
refactor(web/test): add X-SPINNAKER-USER and X-SPINNAKER-ACCOUNTS hea…
dbyron-sf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
144 changes: 144 additions & 0 deletions
144
gate-web/src/test/java/com/netflix/spinnaker/gate/service/PipelineServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* Copyright 2025 OpsMx, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.gate.service; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; | ||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; | ||
import static com.netflix.spinnaker.kork.common.Header.REQUEST_ID; | ||
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.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.github.tomakehurst.wiremock.client.WireMock; | ||
import com.github.tomakehurst.wiremock.junit5.WireMockExtension; | ||
import com.netflix.spinnaker.gate.Main; | ||
import com.netflix.spinnaker.gate.health.DownstreamServicesHealthIndicator; | ||
import com.netflix.spinnaker.gate.services.internal.ClouddriverService; | ||
import com.netflix.spinnaker.gate.services.internal.ClouddriverServiceSelector; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInfo; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.web.context.WebApplicationContext; | ||
import retrofit2.mock.Calls; | ||
|
||
@SpringBootTest(classes = Main.class) | ||
@TestPropertySource( | ||
properties = { | ||
"spring.config.location=classpath:gate-test.yml", | ||
"services.front50.applicationRefreshInitialDelayMs=3600000" | ||
}) | ||
public class PipelineServiceTest { | ||
private MockMvc webAppMockMvc; | ||
|
||
@RegisterExtension | ||
static WireMockExtension wmOrca = | ||
WireMockExtension.newInstance().options(wireMockConfig().dynamicPort()).build(); | ||
|
||
@Autowired private WebApplicationContext webApplicationContext; | ||
|
||
@Autowired ObjectMapper objectMapper; | ||
|
||
/** | ||
* This takes X-SPINNAKER-* headers from requests to gate and puts them in the MDC. This is | ||
* enabled when gate runs normally (by GateConfig), but needs explicit mention to function in | ||
* these tests. | ||
*/ | ||
@Autowired | ||
@Qualifier("authenticatedRequestFilter") | ||
private FilterRegistrationBean filterRegistrationBean; | ||
|
||
@MockBean ClouddriverServiceSelector clouddriverServiceSelector; | ||
|
||
@MockBean ClouddriverService clouddriverService; | ||
|
||
/** To prevent periodic calls to service's /health endpoints */ | ||
@MockBean DownstreamServicesHealthIndicator downstreamServicesHealthIndicator; | ||
|
||
private static final String SUBMITTED_REQUEST_ID = "submitted-request-id"; | ||
private static final String PIPELINE_EXECUTION_ID = "my-pipeline-execution-id"; | ||
|
||
@DynamicPropertySource | ||
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); | ||
} | ||
|
||
@BeforeEach | ||
void init(TestInfo testInfo) { | ||
System.out.println("--------------- Test " + testInfo.getDisplayName()); | ||
|
||
webAppMockMvc = | ||
webAppContextSetup(webApplicationContext) | ||
.addFilters(filterRegistrationBean.getFilter()) | ||
.build(); | ||
|
||
// Keep the background thread that refreshes the applications cache in | ||
// ApplicationService happy. | ||
when(clouddriverServiceSelector.select()).thenReturn(clouddriverService); | ||
when(clouddriverService.getAllApplicationsUnrestricted(anyBoolean())) | ||
.thenReturn(Calls.response(Collections.emptyList())); | ||
} | ||
|
||
@Test | ||
void invokeDeletePipelineExecution() throws Exception { | ||
wmOrca.stubFor( | ||
WireMock.get(urlEqualTo("/pipelines/" + PIPELINE_EXECUTION_ID)) | ||
.willReturn( | ||
aResponse() | ||
.withStatus(200) | ||
.withBody(objectMapper.writeValueAsString(Map.of("foo", "bar"))))); | ||
|
||
// simulate Orca response to the delete request | ||
wmOrca.stubFor( | ||
WireMock.delete(urlEqualTo("/pipelines/" + PIPELINE_EXECUTION_ID)) | ||
.willReturn(aResponse().withStatus(200))); | ||
|
||
// TODO: Fix the response type of gate's delete pipeline execution endpoint | ||
// which is supposed to be void instead of Map as Orca doesn't return anything. | ||
webAppMockMvc | ||
.perform( | ||
delete("/pipelines/" + PIPELINE_EXECUTION_ID) | ||
.header(REQUEST_ID.getHeader(), SUBMITTED_REQUEST_ID)) | ||
.andDo(print()) | ||
.andExpect(status().is5xxServerError()) | ||
.andExpect( | ||
status() | ||
.reason( | ||
"Failed to process response body: No content to map due to end-of-input\n" | ||
+ " at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 0]")) | ||
.andExpect(header().string(REQUEST_ID.getHeader(), SUBMITTED_REQUEST_ID)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this in these tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean autowiring of ObjectMapper? It's not. I will update. But if you are asking whether ObjectMapper is needed at all, there is a usage in the test to create the response body string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was asking about the FilterRegistrationBean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it turns out that it is needed to silence warnings about e.g. missing X-SPINNAKER-USER, X-SPINNAKER-ACCOUNTS warnings...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed some commits to silence those warnings, and some others.