Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ buildscript {
classpath 'com.palantir.jakartapackagealignment:jakarta-package-alignment:0.6.0'
classpath 'com.palantir.gradle.jdks:gradle-jdks:0.69.0'
classpath 'com.palantir.gradle.jdkslatest:gradle-jdks-latest:0.24.0'
classpath 'com.palantir.gradle.plugintesting:gradle-plugin-testing:0.43.0'
classpath 'com.palantir.gradle.externalpublish:gradle-external-publish-plugin:1.27.0'
classpath 'com.palantir.javaformat:gradle-palantir-java-format:2.83.0'
classpath 'com.palantir.suppressible-error-prone:gradle-suppressible-error-prone:2.26.0'
Expand Down
1 change: 1 addition & 0 deletions environment-variables/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies {
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'com.netflix.nebula:nebula-test'
testImplementation 'com.palantir.gradle.plugintesting:gradle-plugin-testing-junit'
}

tasks.withType(Test).configureEach {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* (c) Copyright 2023 Palantir Technologies Inc. All rights reserved.
*
* 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.palantir.gradle.utils.environmentvariables;

import static com.palantir.gradle.testing.assertion.GradlePluginTestAssertions.assertThat;

import com.palantir.gradle.testing.execution.GradleInvoker;
import com.palantir.gradle.testing.execution.InvocationResult;
import com.palantir.gradle.testing.files.gradle.GradleFile;
import com.palantir.gradle.testing.junit.DisabledConfigurationCache;
import com.palantir.gradle.testing.junit.GradlePluginTests;
import com.palantir.gradle.testing.project.RootProject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

@GradlePluginTests
@DisabledConfigurationCache
class EnvironmentVariablesTest {
@BeforeEach
void setup(RootProject project) {
setupBuildFile(project);
}

private GradleFile setupBuildFile(RootProject project) {
return project.buildGradle().append("""
import com.palantir.gradle.utils.environmentvariables.EnvironmentVariables

public abstract class TestClass {
@Nested
abstract EnvironmentVariables getEnvironmentVariables()
}

def variables = objects.newInstance(TestClass).environmentVariables
println('Variable: ' + variables.envVarOrFromTestingProperty('VARIABLE').getOrNull())
println('isCircleNode0OrLocal: ' + variables.isCircleNode0OrLocal().getOrNull())
println('isCi: ' + variables.isCi().getOrNull())
""");
}

@Test
void can_get_testing_variables(GradleInvoker gradle) {
InvocationResult result = gradle.withArgs("help", "-P__TESTING=true", "-P__TESTING_VARIABLE=test")
.buildsSuccessfully();

assertThat(result).output().contains("Variable: test");
}

@Test
void can_get_environment_variables(GradleInvoker gradle) {
InvocationResult result = gradle.withArgs("help").buildsSuccessfully();

assertThat(result).output().contains("Variable: actual value");
}

@Test
void isCircleNode0OrLocal_returns_true_on_circle_node_0(GradleInvoker gradle) {
InvocationResult result = gradle.withArgs("help", "-P__TESTING=true", "-P__TESTING_CIRCLE_NODE_INDEX=0")
.buildsSuccessfully();

assertThat(result).output().contains("isCircleNode0OrLocal: true");
}

@Test
void isCircleNode0OrLocal_returns_false_on_circle_node_1(GradleInvoker gradle) {
InvocationResult result = gradle.withArgs("help", "-P__TESTING=true", "-P__TESTING_CIRCLE_NODE_INDEX=1")
.buildsSuccessfully();

assertThat(result).output().contains("isCircleNode0OrLocal: false");
}

@Test
void isCircleNode0OrLocal_returns_true_locally(GradleInvoker gradle) {
InvocationResult result = gradle.withArgs("help", "-P__TESTING=true").buildsSuccessfully();

assertThat(result).output().contains("isCircleNode0OrLocal: true");
}

@Test
void isCi_returns_true_on_circle_node(GradleInvoker gradle) {
InvocationResult result = gradle.withArgs("help", "-P__TESTING=true", "-P__TESTING_CI=true")
.buildsSuccessfully();

assertThat(result).output().contains("isCi: true");
}

@Test
void isCi_returns_false_locally(GradleInvoker gradle) {
InvocationResult result = gradle.withArgs("help", "-P__TESTING=true").buildsSuccessfully();

assertThat(result).output().contains("isCi: false");
}

@Test
void isCi_returns_false_if_CI_equals_false(GradleInvoker gradle) {
InvocationResult result = gradle.withArgs("help", "-P__TESTING=true", "-P__TESTING_CI=false")
.buildsSuccessfully();

assertThat(result).output().contains("isCi: false");
}
}
3,042 changes: 3,042 additions & 0 deletions test-migration-notes/EnvironmentVariablesTest.html

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions versions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,43 @@ org.immutables:value:2.11.7 (1 constraints: 3d05393b)

cglib:cglib-nodep:3.2.2 (1 constraints: 490ded24)

com.google.errorprone:error_prone_annotations:2.41.0 (2 constraints: 7e0f1fa1)

com.google.guava:failureaccess:1.0.3 (1 constraints: 160ae3b4)

com.google.guava:guava:33.5.0-jre (1 constraints: 481bc549)

com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918)

com.google.j2objc:j2objc-annotations:3.1 (1 constraints: b809f1a0)

com.netflix.nebula:nebula-test:10.6.2 (1 constraints: 3b053b3b)

com.palantir.gradle.plugintesting:gradle-plugin-testing-junit:0.43.0 (1 constraints: 3905383b)

commons-io:commons-io:2.19.0 (1 constraints: db190cdf)

junit:junit:4.13.2 (1 constraints: 1b0e1d4c)

net.bytebuddy:byte-buddy:1.17.7 (1 constraints: 560b56df)

org.apiguardian:apiguardian-api:1.1.2 (6 constraints: 5366ce6e)

org.assertj:assertj-core:3.27.6 (1 constraints: 4405543b)
org.assertj:assertj-core:3.27.6 (2 constraints: 211f1a90)

org.codehaus.groovy:groovy:3.0.12 (2 constraints: 781b1f9d)

org.hamcrest:hamcrest:2.2 (1 constraints: d20cdc04)

org.hamcrest:hamcrest-core:1.3 (1 constraints: cc05fe3f)

org.jspecify:jspecify:1.0.0 (6 constraints: 4166fe65)
org.jetbrains:annotations:26.0.2 (1 constraints: d9190fdf)

org.jspecify:jspecify:1.0.0 (7 constraints: 5370d26f)

org.junit.jupiter:junit-jupiter:6.0.1 (1 constraints: 48070970)

org.junit.jupiter:junit-jupiter-api:6.0.1 (3 constraints: 5e2fd3d8)
org.junit.jupiter:junit-jupiter-api:6.0.1 (4 constraints: 39496641)

org.junit.jupiter:junit-jupiter-engine:6.0.1 (1 constraints: 040ecb3b)

Expand Down
1 change: 1 addition & 0 deletions versions.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
com.fasterxml.jackson.*:* = 2.20.0
com.fasterxml.jackson.core:jackson-annotations = 2.20
com.palantir.gradle.plugintesting:gradle-plugin-testing-junit = 0.43.0
org.apache.commons:commons-lang3 = 3.20.0

org.junit.jupiter:* = 6.0.1
Expand Down