Skip to content

Commit

Permalink
Add tests exercising v2 buf.yaml syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
drice-buf committed Jul 26, 2024
1 parent fe78fad commit 96cb31d
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 6 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ allprojects {
dependencies {
implementation(libs.jacksonDataformatYaml)
implementation(libs.jacksonModuleKotlin)
implementation(libs.versioncompare)

testImplementation(libs.junit)
testImplementation(libs.truth)
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ spotless = "6.25.0"

# runtime
jackson = "2.17.2"
versioncompare = "1.5.0"

# test
junit = "5.10.3"
Expand All @@ -22,6 +23,7 @@ spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
# runtime
jacksonDataformatYaml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml", version.ref = "jackson" }
jacksonModuleKotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" }
versioncompare = { module = "io.github.g00fy2:versioncompare", version.ref = "versioncompare" }

# test
junit = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
Expand Down
16 changes: 10 additions & 6 deletions src/main/kotlin/build/buf/gradle/BreakingTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,22 @@

package build.buf.gradle

import io.github.g00fy2.versioncompare.Version
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction


abstract class BreakingTask : DefaultTask() {
@TaskAction
fun bufBreaking() {
execBuf(
"breaking",
bufBuildPublicationFile,
"--against",
singleFileFromConfiguration(BUF_BREAKING_CONFIGURATION_NAME),
) {
val args = ArrayList<Any>()
args.add("breaking")
if (Version(project.getExtension().toolVersion) < Version("1.32.0")) {
args.add(bufBuildPublicationFile)
}
args.add("--against")
args.add(singleFileFromConfiguration(BUF_BREAKING_CONFIGURATION_NAME))
execBuf(args) {
"""
|Some Protobuf files had breaking changes:
|$it
Expand Down
10 changes: 10 additions & 0 deletions src/test/kotlin/build/buf/gradle/AbstractBreakingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ abstract class AbstractBreakingTest : AbstractBufIntegrationTest() {
checkRunner().build()
}

@Test
fun `normally breaking schema with an ignore v2`() {
publishRunner().build()

breakSchema()

buildFile.replace("//", "")
checkRunner().build()
}

@Test
fun `breaking schema fails with latest-release and previousVersion`() {
val result = checkRunner().buildAndFail()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: v2
modules:
- path: workspace
breaking:
ignore:
- workspace/buf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
plugins {
id 'java'
id 'build.buf'
id 'maven-publish'
}

repositories {
mavenCentral()
maven { url 'build/repos/test' }
}

publishing {
repositories {
maven { url 'build/repos/test' }
}
}

buf {
publishSchema = true
//previousVersion = '2319'

imageArtifact {
groupId = 'foo'
artifactId = 'bar'
version = '2319'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2023 Buf Technologies, 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.

syntax = "proto3";

package buf.test.v1;

message BasicMessage {}

0 comments on commit 96cb31d

Please sign in to comment.