Skip to content

Commit

Permalink
add new tests for EXTENSION_NO_DELETE and PACKAGE_EXTENSION_NO_DELETE…
Browse files Browse the repository at this point in the history
… rules
  • Loading branch information
jhump committed May 9, 2024
1 parent 1c9e1c3 commit a1de807
Show file tree
Hide file tree
Showing 18 changed files with 445 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,28 @@ func AssertFileAnnotationsEqual(
) {
t.Log("If actuals are correct, change expectations to the following:")
for _, annotation := range actual {
t.Logf(" bufanalysistesting.NewFileAnnotation(t, %q, %d, %d, %d, %d, %q),",
annotation.FileInfo().Path(),
annotation.StartLine(),
annotation.StartColumn(),
annotation.EndLine(),
annotation.EndColumn(),
annotation.Type(),
)
if annotation.StartLine() == 0 && annotation.StartColumn() == 0 &&
annotation.EndLine() == 0 && annotation.EndColumn() == 0 {
if annotation.FileInfo().Path() == "" {
t.Logf(" bufanalysistesting.NewFileAnnotationNoLocationOrPath(t, %q),",
annotation.Type(),
)
} else {
t.Logf(" bufanalysistesting.NewFileAnnotationNoLocation(t, %q, %q),",
annotation.FileInfo().Path(),
annotation.Type(),
)
}
} else {
t.Logf(" bufanalysistesting.NewFileAnnotation(t, %q, %d, %d, %d, %d, %q),",
annotation.FileInfo().Path(),
annotation.StartLine(),
annotation.StartColumn(),
annotation.EndLine(),
annotation.EndColumn(),
annotation.Type(),
)
}
}
}
}
Expand Down
42 changes: 33 additions & 9 deletions private/bufpkg/bufcheck/bufbreaking/bufbreaking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ func TestRunBreakingExtensionMessageNoDelete(t *testing.T) {
)
}

func TestRunBreakingExtensionNoDelete(t *testing.T) {
t.Parallel()
testBreaking(
t,
"breaking_extension_no_delete",
bufanalysistesting.NewFileAnnotationNoLocation(t, "2.proto", "EXTENSION_NO_DELETE"),
bufanalysistesting.NewFileAnnotationNoLocation(t, "2.proto", "EXTENSION_NO_DELETE"),
bufanalysistesting.NewFileAnnotationNoLocation(t, "2.proto", "EXTENSION_NO_DELETE"),
bufanalysistesting.NewFileAnnotationNoLocation(t, "3.proto", "EXTENSION_NO_DELETE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 8, 3, 14, 4, "EXTENSION_NO_DELETE"),
)
}

func TestRunBreakingFieldNoDelete(t *testing.T) {
t.Parallel()
testBreaking(
Expand Down Expand Up @@ -1018,6 +1031,17 @@ func TestRunBreakingOneofNoDelete(t *testing.T) {
)
}

func TestRunBreakingPackageExtensionNoDelete(t *testing.T) {
t.Parallel()
testBreaking(
t,
"breaking_package_extension_no_delete",
bufanalysistesting.NewFileAnnotationNoLocation(t, "2.proto", "PACKAGE_EXTENSION_NO_DELETE"),
bufanalysistesting.NewFileAnnotationNoLocation(t, "3.proto", "PACKAGE_EXTENSION_NO_DELETE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 8, 3, 14, 4, "PACKAGE_EXTENSION_NO_DELETE"),
)
}

func TestRunBreakingPackageNoDelete(t *testing.T) {
t.Parallel()
testBreaking(
Expand All @@ -1038,6 +1062,15 @@ func TestRunBreakingPackageNoDelete(t *testing.T) {
)
}

func TestRunBreakingPackageServiceNoDelete(t *testing.T) {
t.Parallel()
testBreaking(
t,
"breaking_package_service_no_delete",
bufanalysistesting.NewFileAnnotationNoLocation(t, "1.proto", "PACKAGE_SERVICE_NO_DELETE"),
)
}

func TestRunBreakingReservedEnumNoDelete(t *testing.T) {
t.Parallel()
testBreaking(
Expand Down Expand Up @@ -1144,15 +1177,6 @@ func TestRunBreakingServiceNoDelete(t *testing.T) {
)
}

func TestRunBreakingPackageServiceNoDelete(t *testing.T) {
t.Parallel()
testBreaking(
t,
"breaking_package_service_no_delete",
bufanalysistesting.NewFileAnnotationNoLocation(t, "1.proto", "PACKAGE_SERVICE_NO_DELETE"),
)
}

func TestRunBreakingIgnoreUnstablePackagesTrue(t *testing.T) {
t.Parallel()
testBreaking(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
syntax = "proto3";

package a;

message Two {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}

message Three {
message Four {
message Five {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}
message Six {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}
}
message Seven {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}
message Eight {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}
int32 one = 1;
int32 two = 2;
int32 three = 3;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto2";

package a;

import "3.proto";
import "4.proto";

message One {
optional int32 one = 1;
optional int32 two = 2;
}

message Nine {
optional int32 one = 1;
optional int32 three = 3;
}

extend Foo {
optional bytes meta = 20;
optional Foo ch = 22;
}

extend b.Fizz {
optional b.Fizz child = 22;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto2";

package b;

message Fizz {
extensions 10 to 100;

message Buzz {
optional int32 len = 1;

extend Fizz {
optional string str = 10;
}
}
}

extend Fizz {
optional bytes meta = 20;
repeated uint64 tags = 21;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto2";

package a;

message Foo {
extensions 10 to 100;

message Bar {
optional int32 len = 1;

extend Foo {
optional string str = 10;
repeated string labels = 11;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: v2
breaking:
use:
- EXTENSION_NO_DELETE
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
syntax = "proto3";

package a;

message Two {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}

message Three {
message Four {
message Five {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}
message Six {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}
}
message Seven {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}
message Eight {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}
int32 one = 1;
int32 two = 2;
int32 three = 3;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto2";

package a;

import "3.proto";
import "4.proto";

message One {
optional int32 one = 1;
optional int32 two = 2;
}

message Nine {
optional int32 one = 1;
optional int32 three = 3;
}

extend Foo {
optional bytes meta = 20;
optional Foo ch = 22;
}

extend b.Fizz {
optional b.Fizz child = 22;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto2";

package b;

message Fizz {
extensions 10 to 100;

message Buzz {
optional int32 len = 1;

extend Fizz {
optional string str = 10;
}
}
}

extend Fizz {
optional bytes meta = 20;
repeated uint64 tags = 21;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto2";

package a;

message Foo {
extensions 10 to 100;

message Bar {
optional int32 len = 1;

extend Foo {
optional string str = 10;
repeated string labels = 11;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: v2
breaking:
use:
- PACKAGE_EXTENSION_NO_DELETE
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
syntax = "proto3";

package a;

message One {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}

message Two {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}

message Three {
message Four {
message Five {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}
message Six {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}
}
message Seven {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}
message Eight {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}
int32 one = 1;
int32 two = 2;
int32 three = 3;
}

message Nine {
int32 one = 1;
int32 two = 2;
int32 three = 3;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto2";

package a;

message Foo {
extensions 10 to 100;

message Bar {
optional int32 len = 1;

extend Foo {
optional string str = 10;
repeated string labels = 11;
}
}
}

extend Foo {
optional bytes meta = 20;
repeated uint64 tags = 21;
optional Foo ch = 22;
}

0 comments on commit a1de807

Please sign in to comment.