Skip to content
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

Update tests to use local generation #230

Merged
merged 2 commits into from
Aug 27, 2024
Merged
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
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ plugins {
alias(libs.plugins.buildConfig)
alias(libs.plugins.kotlin)
alias(libs.plugins.mavenPublish)
alias(libs.plugins.osDetector)
alias(libs.plugins.pluginPublish)
alias(libs.plugins.spotless)
}
Expand All @@ -33,6 +34,7 @@ allprojects {
}

val bufCliDependabotConfig = configurations.create("bufCliDependabotConfig")
val protoc: Configuration by configurations.creating

dependencies {
// Trigger dependabot on a new Buf CLI release.
Expand All @@ -44,6 +46,7 @@ dependencies {

testImplementation(libs.junit)
testImplementation(libs.truth)
protoc("com.google.protobuf:protoc:${libs.versions.protoc.get()}:${osdetector.classifier}@exe")
}

object ProjectInfo {
Expand Down Expand Up @@ -119,6 +122,8 @@ tasks {

withType<Test> {
useJUnitPlatform()

systemProperty("protoc.path", protoc.asPath)
}

withType<KotlinCompile> {
Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
# plugins
kotlin = "1.9.24"
mavenPublish = "0.29.0"
osDetector = "1.7.3"
pluginPublish = "1.2.1"
spotless = "6.25.0"
buildConfig = "5.4.0"

# runtime
bufbuild = "1.38.0"
jackson = "2.17.2"
protoc = "3.23.4"
versioncompare = "1.5.0"

# test
Expand All @@ -19,6 +21,7 @@ truth = "1.4.4"
buildConfig = { id = "com.github.gmazzo.buildconfig", version.ref = "buildConfig" }
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
mavenPublish = { id = "com.vanniktech.maven.publish.base", version.ref = "mavenPublish" }
osDetector = { id = "com.google.osdetector", version.ref = "osDetector" }
pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "pluginPublish" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }

Expand All @@ -27,6 +30,7 @@ spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
bufbuild = { module = "build.buf:buf", version.ref = "bufbuild" }
jacksonDataformatYaml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml", version.ref = "jackson" }
jacksonModuleKotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" }
protoc = { module = "com.google.protobuf:protoc", version.ref = "protoc" }
versioncompare = { module = "io.github.g00fy2:versioncompare", version.ref = "versioncompare" }

# test
Expand Down
16 changes: 16 additions & 0 deletions src/test/kotlin/build/buf/gradle/AbstractGenerateTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,26 @@ package build.buf.gradle

import com.google.common.truth.Truth.assertThat
import org.gradle.language.base.plugins.LifecycleBasePlugin.BUILD_TASK_NAME
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.io.File
import java.nio.file.Paths

abstract class AbstractGenerateTest : AbstractBufIntegrationTest() {
@BeforeEach
fun configureBufGenYamlProtocPath() {
val protocPath = System.getProperty("protoc.path") ?: error("protoc.path not set")
val protocFile = File(protocPath)
if (!protocFile.canExecute()) {
protocFile.setExecutable(true)
}
projectDir.walkTopDown().forEach { file ->
if (file.name == "buf.gen.yaml") {
file.replace("PROTOC_PATH", protocFile.absolutePath)
}
}
}

@Test
fun `generate java`() {
gradleRunner().withArguments(BUILD_TASK_NAME).build()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
4 changes: 3 additions & 1 deletion src/test/resources/GenerateTest/generate_java/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/java:v23.4
- plugin: java
# Replaced with full path to protoc in test setup.
protoc_path: PROTOC_PATH
out: java