Skip to content

Commit

Permalink
Introduce ability to override 'build/nebulatest' for projectDir on te…
Browse files Browse the repository at this point in the history
…stkit based specs
  • Loading branch information
rpalcolea committed Feb 23, 2024
1 parent b3de807 commit 5b45a92
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/groovy/nebula/test/IntegrationBase.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ abstract trait IntegrationBase {

private static final String LOGGING_LEVEL_ENV_VARIABLE = "NEBULA_TEST_LOGGING_LEVEL"

def initialize(Class<?> testClass, String testMethodName) {
projectDir = new File("build/nebulatest/${testClass.canonicalName}/${testMethodName.replaceAll(/\W+/, '-')}").absoluteFile
def initialize(Class<?> testClass, String testMethodName, String baseFolderName = 'nebulatest') {
projectDir = new File("build/${baseFolderName}/${testClass.canonicalName}/${testMethodName.replaceAll(/\W+/, '-')}").absoluteFile
if (projectDir.exists()) {
projectDir.deleteDir()
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/groovy/nebula/test/IntegrationTestKitBase.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ abstract trait IntegrationTestKitBase extends IntegrationBase {
boolean definePluginOutsideOfPluginBlock = false

@Override
def initialize(Class<?> testClass, String testMethodName) {
super.initialize(testClass, testMethodName)
def initialize(Class<?> testClass, String testMethodName, String baseFolderName = 'nebulatest') {
super.initialize(testClass, testMethodName, baseFolderName)
if (!settingsFile) {
settingsFile = new File(projectDir, "settings.gradle")
settingsFile.text = "rootProject.name='${moduleName}'\n"
Expand Down
6 changes: 5 additions & 1 deletion src/main/groovy/nebula/test/IntegrationTestKitSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ abstract class IntegrationTestKitSpec extends Specification implements Integrati
@Rule
TestName testName = new TestName()

String getProjectBaseFolderName() {
return 'nebulatest'
}

void setup() {
IntegrationTestKitBase.super.initialize(getClass(), testName.methodName)
IntegrationTestKitBase.super.initialize(getClass(), testName.methodName, getProjectBaseFolderName())
}

void cleanup() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
*
* Copyright 2020 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 nebula.test

class IntegrationTestKitSpecCustomBaseFolderSpec extends IntegrationTestKitSpec {

def setup() {
// used to test trait & groovy setup method https://stackoverflow.com/questions/56464191/public-groovy-method-must-be-public-says-the-compiler
}

def cleanup() {
// used to test trait & groovy cleanup method https://stackoverflow.com/questions/56464191/public-groovy-method-must-be-public-says-the-compiler
}

@Override
String getProjectBaseFolderName() {
return 'notnebulatest'
}

def 'can override project dir base folder name'() {
expect:
!projectDir.absolutePath.contains("/build/nebulatest/")
projectDir.absolutePath.contains("/build/notnebulatest/")
}
}

0 comments on commit 5b45a92

Please sign in to comment.