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

Add v2 buf.yaml LintWithWorkspaceTest test cases #215

Merged
merged 3 commits into from
Jul 29, 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
30 changes: 30 additions & 0 deletions src/test/kotlin/build/buf/gradle/LintWithWorkspaceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,34 @@ class LintWithWorkspaceTest : NonProtobufGradlePluginLintTests, AbstractLintTest
fun `lint with a config in workspace`() {
assertSuccess()
}

@Test
fun `lint a basic correct message with default config v2`() {
super.`lint a basic correct message with default config`()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh. Do you have plans to hoist this up into the base test classes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you suggest as a good idiom for two tests that do exactly the same thing but use different resource dirs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only added a _v2 test for cases that contain a buf.work.yaml file, which are generally the WithWorkspace tests. Accordingly I define these cases only in the leaf classes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good idiom for exactly this case. My question was more about: these super tests are also applicable to situations in which ones doesn't use workspaces, and those still run against v1 buf.yamls. Defining these tests in the base classes will allow the test suite to declare it supports v2 configs for each of the three scenarios.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The super function is itself a @Test case that runs against the resource dir that does not end with _v2

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right - and would it also make sense to run v2 tests against a "vanilla" project (i.e., one not using workspaces)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to test against every version of Buf CLI - apart from some edge cases which we unfortunately ran into, it is meant to be fully backwards compatible.

}

@Test
fun `lint a basic correct message with default config before java plugin v2`() {
super.`lint a basic correct message with default config before java plugin`()
}

@Test
fun `lint a basic correct message with default config and the kotlin jvm plugin v2`() {
super.`lint a basic correct message with default config and the kotlin jvm plugin`()
}

@Test
fun `lint a basic correct message with default config and the kotlin android plugin v2`() {
super.`lint a basic correct message with default config and the kotlin android plugin`()
}

@Test
fun `lint a basic incorrect message with bad enum v2`() {
super.`lint a basic incorrect message with bad enum`()
}

@Test
fun `lint a file with a google dependency v2`() {
super.`lint a file with a google dependency`()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: v2
modules:
- path: workspace
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own understanding - is buf.work.yaml just not a thing anymore in v2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://buf.build/docs/configuration/v1/buf-work-yaml:

Buf now has a v2 configuration available, where this file is no longer used.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
buildscript {
repositories {
gradlePluginPortal()
google()
}

dependencies {
classpath "com.android.tools.build:gradle:$androidGradleVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}

plugins {
id 'build.buf'
}

apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.android'

repositories {
mavenCentral()
google()
}

android {
compileSdkVersion 31
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="buf">
</manifest>
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 {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: v2
modules:
- path: workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version "$kotlinVersion"
id 'build.buf'
}

repositories {
mavenCentral()
}
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 {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: v2
modules:
- path: workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id 'build.buf'
id 'java'
}

repositories {
mavenCentral()
}
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 {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: v2
modules:
- path: workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id 'java'
id 'build.buf'
}

repositories {
mavenCentral()
}
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 {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: v2
modules:
- path: workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id 'java'
id 'build.buf'
}

repositories {
mavenCentral()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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;

enum Test {
TEST_FOO = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: v2
modules:
- path: workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id 'java'
id 'build.buf'
}

repositories {
mavenCentral()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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;

import "google/protobuf/any.proto";

message BasicMessage {
google.protobuf.Any any = 1;
}