forked from spinnaker/orca
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(executions): Adding new ADMIN endpoint to import execution (spin…
…naker#3310) * feat(executions): Adding new endpoint to import execution from another spinnaker instance. Useful to get a execution into other envs for troubleshooting. Only imports executions with TERMINAL, SUCCEEDED or CANCELLED states. * Disallow if execution already exists and also add some info helper messages
- Loading branch information
1 parent
24b5b40
commit da46413
Showing
2 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
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
80 changes: 80 additions & 0 deletions
80
orca-web/src/test/groovy/com/netflix/spinnaker/orca/controllers/AdminControllerSpec.groovy
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,80 @@ | ||
/* | ||
* Copyright 2019 Netflix, 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.orca.controllers | ||
|
||
import com.netflix.spinnaker.kork.web.exceptions.InvalidRequestException | ||
import com.netflix.spinnaker.orca.ExecutionStatus | ||
import com.netflix.spinnaker.orca.pipeline.model.Execution | ||
import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionNotFoundException | ||
import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository | ||
import de.huxhorn.sulky.ulid.ULID | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
class AdminControllerSpec extends Specification { | ||
|
||
ExecutionRepository executionRepository = Mock(ExecutionRepository) | ||
|
||
AdminController controller = new AdminController(executionRepository: executionRepository) | ||
|
||
def setup() { | ||
executionRepository = Mock(ExecutionRepository) | ||
controller = new AdminController(executionRepository: executionRepository) | ||
} | ||
|
||
@Unroll | ||
def 'should throw error while saving execution with status: #invalidStatus '() { | ||
given: | ||
String executionId = new ULID().nextULID() | ||
Execution execution = new Execution(Execution.ExecutionType.PIPELINE, executionId, 'testapp') | ||
|
||
when: | ||
execution.status = invalidStatus | ||
controller.createExecution(execution) | ||
|
||
then: | ||
thrown(InvalidRequestException) | ||
1 * executionRepository.retrieve(Execution.ExecutionType.PIPELINE, executionId) >> { throw new ExecutionNotFoundException('No execution')} | ||
0 * _ | ||
|
||
where: | ||
invalidStatus << [ExecutionStatus.RUNNING, ExecutionStatus.PAUSED, ExecutionStatus.NOT_STARTED] | ||
} | ||
|
||
@Unroll | ||
def 'should succeed while saving execution with status: #validStatus '() { | ||
given: | ||
String executionId = new ULID().nextULID() | ||
Execution execution = new Execution(Execution.ExecutionType.PIPELINE, executionId, 'testapp') | ||
|
||
when: | ||
execution.status = validStatus | ||
Map result = controller.createExecution(execution) | ||
|
||
then: | ||
noExceptionThrown() | ||
1 * executionRepository.retrieve(Execution.ExecutionType.PIPELINE, executionId) >> { throw new ExecutionNotFoundException('No execution')} | ||
1 * executionRepository.store(execution) | ||
0 * _ | ||
result.executionId == executionId | ||
result.status == validStatus | ||
|
||
where: | ||
validStatus << [ExecutionStatus.SUCCEEDED, ExecutionStatus.CANCELED, ExecutionStatus.TERMINAL] | ||
} | ||
|
||
} |