-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MPL-32 Moved to CPS tests by default
- Loading branch information
Sergei Parshev
committed
Nov 6, 2019
1 parent
807fc47
commit 8c434f5
Showing
7 changed files
with
201 additions
and
56 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
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
41 changes: 41 additions & 0 deletions
41
test/groovy/com/griddynamics/devops/mpl/testing/MPLTestBaseNonCPS.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,41 @@ | ||
// | ||
// Copyright (c) 2018 Grid Dynamics International, Inc. All Rights Reserved | ||
// https://www.griddynamics.com | ||
// | ||
// Classification level: Public | ||
// | ||
// 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. | ||
// | ||
// $Id: $ | ||
// @Project: MPL | ||
// @Description: Shared Jenkins Modular Pipeline Library | ||
// | ||
|
||
package com.griddynamics.devops.mpl.testing | ||
|
||
import com.griddynamics.devops.mpl.testing.MPLTestBaseSetup | ||
import com.lesfurets.jenkins.unit.BasePipelineTest | ||
|
||
import com.griddynamics.devops.mpl.testing.MPLTestHelper | ||
|
||
// It's not recommended to use non-cps class for testing - use MPLTestBase instead | ||
abstract class MPLTestBaseNonCPS extends BasePipelineTest { | ||
MPLTestBaseNonCPS() { | ||
helper = new MPLTestHelperNonCPS() | ||
} | ||
|
||
void setUp() throws Exception { | ||
super.setUp() | ||
MPLTestBaseSetup.setUp(helper, this.binding) | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
test/groovy/com/griddynamics/devops/mpl/testing/MPLTestBaseSetup.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,63 @@ | ||
// | ||
// Copyright (c) 2019 Grid Dynamics International, Inc. All Rights Reserved | ||
// https://www.griddynamics.com | ||
// | ||
// Classification level: Public | ||
// | ||
// 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. | ||
// | ||
// $Id: $ | ||
// @Project: MPL | ||
// @Description: Shared Jenkins Modular Pipeline Library | ||
// | ||
|
||
package com.griddynamics.devops.mpl.testing | ||
|
||
import com.griddynamics.devops.mpl.MPLManager | ||
import com.griddynamics.devops.mpl.Helper | ||
|
||
import org.codehaus.groovy.runtime.InvokerHelper | ||
|
||
abstract class MPLTestBaseSetup { | ||
static void setUp(helper, context) throws Exception { | ||
// Overriding Helper to find the right resources in the loaded libs | ||
Helper.metaClass.static.getModulesList = { String path -> | ||
def modules = [] | ||
def resourcesFolder = helper.getLibraryClassLoader().getResource('.').getFile() | ||
MPLManager.instance.getModulesLoadPaths().each { modulesPath -> | ||
def libPath = modulesPath + '/' + path | ||
helper.getLibraryClassLoader().getResources(libPath).each { res -> | ||
def libname = res.getFile().substring(resourcesFolder.length()) | ||
libname = libname.substring(0, Math.max(libname.indexOf('@'), 0)) | ||
modules += [[libname + '/' + libPath, res.text]] | ||
} | ||
} | ||
return modules | ||
} | ||
|
||
// Replacing runModule function to mock it | ||
Helper.metaClass.static.runModule = { String source, String path, Map vars = [:] -> | ||
def binding = new Binding() | ||
context.variables.each { k, v -> binding.setVariable(k, v) } | ||
vars.each { k, v -> binding.setVariable(k, v) } | ||
def script = InvokerHelper.createScript(helper.getLibraryClassLoader().parseClass(new GroovyCodeSource(source, path, '/mpl/modules'), false), binding) | ||
script.metaClass.invokeMethod = helper.getMethodInterceptor() | ||
script.metaClass.static.invokeMethod = helper.getMethodInterceptor() | ||
script.metaClass.methodMissing = helper.getMethodMissingInterceptor() | ||
script.run() | ||
} | ||
|
||
// Show the dump of the configuration during unit tests execution | ||
Helper.metaClass.static.configEntrySet = { Map config -> config.entrySet() } | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
test/groovy/com/griddynamics/devops/mpl/testing/MPLTestHelperNonCPS.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,43 @@ | ||
// | ||
// Copyright (c) 2018 Grid Dynamics International, Inc. All Rights Reserved | ||
// https://www.griddynamics.com | ||
// | ||
// Classification level: Public | ||
// | ||
// 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. | ||
// | ||
// $Id: $ | ||
// @Project: MPL | ||
// @Description: Shared Jenkins Modular Pipeline Library | ||
// | ||
|
||
package com.griddynamics.devops.mpl.testing | ||
|
||
import com.lesfurets.jenkins.unit.PipelineTestHelper | ||
import com.lesfurets.jenkins.unit.MethodSignature | ||
|
||
@groovy.transform.InheritConstructors | ||
class MPLTestHelperNonCPS extends PipelineTestHelper { | ||
public getLibraryConfig() { | ||
gse.getConfig() | ||
} | ||
public getLibraryClassLoader() { | ||
gse.groovyClassLoader | ||
} | ||
|
||
void registerAllowedMethod(MethodSignature methodSignature, Closure closure) { | ||
if( isMethodAllowed(methodSignature.name, methodSignature.args) ) | ||
return // Skipping methods already existing in the list | ||
allowedMethodCallbacks.put(methodSignature, closure) | ||
} | ||
} |
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