diff --git a/private/buf/cmd/buf/testdata/workspace/fail/v2/absolute/buf.yaml b/private/buf/cmd/buf/testdata/workspace/fail/v2/absolute/buf.yaml new file mode 100644 index 0000000000..672a579db9 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/fail/v2/absolute/buf.yaml @@ -0,0 +1,3 @@ +version: v2 +modules: + - directory: /home/buf diff --git a/private/buf/cmd/buf/testdata/workspace/fail/v2/absolute/windows/buf.yaml b/private/buf/cmd/buf/testdata/workspace/fail/v2/absolute/windows/buf.yaml new file mode 100644 index 0000000000..d2ff473b22 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/fail/v2/absolute/windows/buf.yaml @@ -0,0 +1,3 @@ +version: v2 +modules: + - directory: C:\buf diff --git a/private/buf/cmd/buf/testdata/workspace/fail/v2/duplicate/buf.yaml b/private/buf/cmd/buf/testdata/workspace/fail/v2/duplicate/buf.yaml new file mode 100644 index 0000000000..bbb4cc2c6f --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/fail/v2/duplicate/buf.yaml @@ -0,0 +1,4 @@ +version: v2 +modules: + - directory: other/proto + - directory: proto diff --git a/private/buf/cmd/buf/testdata/workspace/fail/v2/duplicate/other/proto/foo.proto b/private/buf/cmd/buf/testdata/workspace/fail/v2/duplicate/other/proto/foo.proto new file mode 100644 index 0000000000..2854c3eac1 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/fail/v2/duplicate/other/proto/foo.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package foo; + +message Foo {} + +message Bar {} diff --git a/private/buf/cmd/buf/testdata/workspace/fail/v2/duplicate/proto/foo.proto b/private/buf/cmd/buf/testdata/workspace/fail/v2/duplicate/proto/foo.proto new file mode 100644 index 0000000000..d2b2ff478d --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/fail/v2/duplicate/proto/foo.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +package foo; + +message Foo {} diff --git a/private/buf/cmd/buf/testdata/workspace/fail/v2/jumpcontext/buf.yaml b/private/buf/cmd/buf/testdata/workspace/fail/v2/jumpcontext/buf.yaml new file mode 100644 index 0000000000..181798bf70 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/fail/v2/jumpcontext/buf.yaml @@ -0,0 +1,3 @@ +version: v2 +modules: + - directory: ../breaking/other/proto diff --git a/private/buf/cmd/buf/testdata/workspace/fail/v2/notexist/buf.yaml b/private/buf/cmd/buf/testdata/workspace/fail/v2/notexist/buf.yaml new file mode 100644 index 0000000000..f787a654c8 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/fail/v2/notexist/buf.yaml @@ -0,0 +1,3 @@ +version: v2 +modules: + - directory: notexist diff --git a/private/buf/cmd/buf/testdata/workspace/fail/v2/symlink/a/a.proto b/private/buf/cmd/buf/testdata/workspace/fail/v2/symlink/a/a.proto new file mode 100644 index 0000000000..dd154287f8 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/fail/v2/symlink/a/a.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package a; + +import "b.proto"; + +message A { + b.B b = 1; +} diff --git a/private/buf/cmd/buf/testdata/workspace/fail/v2/symlink/b b/private/buf/cmd/buf/testdata/workspace/fail/v2/symlink/b new file mode 120000 index 0000000000..823171a98d --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/fail/v2/symlink/b @@ -0,0 +1 @@ +../../../success/v2/transitive/private/proto \ No newline at end of file diff --git a/private/buf/cmd/buf/testdata/workspace/fail/v2/symlink/buf.yaml b/private/buf/cmd/buf/testdata/workspace/fail/v2/symlink/buf.yaml new file mode 100644 index 0000000000..eb69a3873d --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/fail/v2/symlink/buf.yaml @@ -0,0 +1,4 @@ +version: v2 +modules: + - directory: a + - directory: b diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/breaking/a/proto/a/v1/a.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/breaking/a/proto/a/v1/a.proto new file mode 100644 index 0000000000..804b20cf5b --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/breaking/a/proto/a/v1/a.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +package a.v1; + +message A {} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/breaking/buf.yaml b/private/buf/cmd/buf/testdata/workspace/success/v2/breaking/buf.yaml new file mode 100644 index 0000000000..a747760e4f --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/breaking/buf.yaml @@ -0,0 +1,7 @@ +version: v2 +modules: + - directory: a/proto + - directory: other/proto + name: bufbuild.test/workspace/request + - directory: proto + name: bufbuild.test/workspace/rpc diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/breaking/other/proto/request.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/breaking/other/proto/request.proto new file mode 100644 index 0000000000..8a399b1557 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/breaking/other/proto/request.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +package request; + +message Request {} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/breaking/proto/rpc.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/breaking/proto/rpc.proto new file mode 100644 index 0000000000..964e158159 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/breaking/proto/rpc.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package example; + +import "request.proto"; + +message RPC { + request.Request request = 1; +} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/detached/buf.yaml b/private/buf/cmd/buf/testdata/workspace/success/v2/detached/buf.yaml new file mode 100644 index 0000000000..ccf1a7bfb6 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/detached/buf.yaml @@ -0,0 +1,3 @@ +version: v2 +modules: + - directory: other/proto diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/detached/other/proto/request.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/detached/other/proto/request.proto new file mode 100644 index 0000000000..5518e6cb53 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/detached/other/proto/request.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package request; + +message Request { + string name = 1; +} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/detached/proto/rpc.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/detached/proto/rpc.proto new file mode 100644 index 0000000000..339aa8d9fe --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/detached/proto/rpc.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package example; + +import "request.proto"; + +message RPC { + request.Request req = 1; +} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/diamond/buf.yaml b/private/buf/cmd/buf/testdata/workspace/success/v2/diamond/buf.yaml new file mode 100644 index 0000000000..6dd06cf9da --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/diamond/buf.yaml @@ -0,0 +1,12 @@ +version: v2 +modules: + - directory: other/proto + - directory: private/proto + - directory: proto + name: bufbuild.test/workspace/first + lint: + except: + - PACKAGE_NO_IMPORT_CYCLE +deps: + - bufbuild.test/workspace/second + - bufbuild.test/workspace/third diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/diamond/other/proto/c.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/diamond/other/proto/c.proto new file mode 100644 index 0000000000..e115994e98 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/diamond/other/proto/c.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +package c; + +message C {} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/diamond/private/proto/b.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/diamond/private/proto/b.proto new file mode 100644 index 0000000000..b4c8652a60 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/diamond/private/proto/b.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package b; + +import "c.proto"; + +message B { + c.C c = 1; +} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/diamond/proto/a.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/diamond/proto/a.proto new file mode 100644 index 0000000000..9955a1031b --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/diamond/proto/a.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package a; + +import "b.proto"; +import "c.proto"; + +message A { + b.B b = 1; + c.C c = 2; +} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/diamond/proto/buf.yaml b/private/buf/cmd/buf/testdata/workspace/success/v2/diamond/proto/buf.yaml new file mode 100644 index 0000000000..8f8591de9a --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/diamond/proto/buf.yaml @@ -0,0 +1,5 @@ +version: v1 +name: bufbuild.test/workspace/first +deps: + - bufbuild.test/workspace/second + - bufbuild.test/workspace/third diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/dir/a/proto/a/v1/a.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/dir/a/proto/a/v1/a.proto new file mode 100644 index 0000000000..804b20cf5b --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/dir/a/proto/a/v1/a.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +package a.v1; + +message A {} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/dir/buf.yaml b/private/buf/cmd/buf/testdata/workspace/success/v2/dir/buf.yaml new file mode 100644 index 0000000000..a747760e4f --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/dir/buf.yaml @@ -0,0 +1,7 @@ +version: v2 +modules: + - directory: a/proto + - directory: other/proto + name: bufbuild.test/workspace/request + - directory: proto + name: bufbuild.test/workspace/rpc diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/dir/other/proto/request.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/dir/other/proto/request.proto new file mode 100644 index 0000000000..5518e6cb53 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/dir/other/proto/request.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package request; + +message Request { + string name = 1; +} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/dir/proto/rpc.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/dir/proto/rpc.proto new file mode 100644 index 0000000000..339aa8d9fe --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/dir/proto/rpc.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package example; + +import "request.proto"; + +message RPC { + request.Request req = 1; +} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/nested/proto/buf.yaml b/private/buf/cmd/buf/testdata/workspace/success/v2/nested/proto/buf.yaml new file mode 100644 index 0000000000..ea56b3a902 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/nested/proto/buf.yaml @@ -0,0 +1,8 @@ +version: v2 +modules: + - directory: external + name: bufbuild.test/workspace/external + - directory: internal + name: bufbuild.test/workspace/internal +deps: + - bufbuild.test/workspace/external diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/nested/proto/external/external.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/nested/proto/external/external.proto new file mode 100644 index 0000000000..9a84537727 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/nested/proto/external/external.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package external; + +message External { + string name = 1; +} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/nested/proto/internal/internal.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/nested/proto/internal/internal.proto new file mode 100644 index 0000000000..83c93a2d32 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/nested/proto/internal/internal.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package internal; + +import "external.proto"; + +message Internal { + external.External external = 1; +} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/symlink/a/a.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/symlink/a/a.proto new file mode 100644 index 0000000000..dd154287f8 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/symlink/a/a.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package a; + +import "b.proto"; + +message A { + b.B b = 1; +} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/symlink/b b/private/buf/cmd/buf/testdata/workspace/success/v2/symlink/b new file mode 120000 index 0000000000..480a36fc0e --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/symlink/b @@ -0,0 +1 @@ +../transitive/private/proto \ No newline at end of file diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/symlink/buf.yaml b/private/buf/cmd/buf/testdata/workspace/success/v2/symlink/buf.yaml new file mode 100644 index 0000000000..6b48f53104 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/symlink/buf.yaml @@ -0,0 +1,5 @@ +version: v2 +modules: + - directory: a + - directory: b + - directory: c diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/symlink/c/c.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/symlink/c/c.proto new file mode 100644 index 0000000000..e115994e98 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/symlink/c/c.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +package c; + +message C {} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/transitive/buf.yaml b/private/buf/cmd/buf/testdata/workspace/success/v2/transitive/buf.yaml new file mode 100644 index 0000000000..1264d01410 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/transitive/buf.yaml @@ -0,0 +1,17 @@ +version: v2 +modules: + - directory: other/proto + name: bufbuild.test/workspace/third + lint: + except: + - PACKAGE_NO_IMPORT_CYCLE + - directory: private/proto + name: bufbuild.test/workspace/second + lint: + except: + - PACKAGE_NO_IMPORT_CYCLE + - directory: proto + name: bufbuild.test/workspace/first + lint: + except: + - PACKAGE_NO_IMPORT_CYCLE diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/transitive/other/proto/c.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/transitive/other/proto/c.proto new file mode 100644 index 0000000000..e115994e98 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/transitive/other/proto/c.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +package c; + +message C {} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/transitive/private/proto/b.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/transitive/private/proto/b.proto new file mode 100644 index 0000000000..b4c8652a60 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/transitive/private/proto/b.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package b; + +import "c.proto"; + +message B { + c.C c = 1; +} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/transitive/proto/a.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/transitive/proto/a.proto new file mode 100644 index 0000000000..dd154287f8 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/transitive/proto/a.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package a; + +import "b.proto"; + +message A { + b.B b = 1; +} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/wkt/buf.yaml b/private/buf/cmd/buf/testdata/workspace/success/v2/wkt/buf.yaml new file mode 100644 index 0000000000..bbb4cc2c6f --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/wkt/buf.yaml @@ -0,0 +1,4 @@ +version: v2 +modules: + - directory: other/proto + - directory: proto diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/wkt/other/proto/c/c.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/wkt/other/proto/c/c.proto new file mode 100644 index 0000000000..642a214133 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/wkt/other/proto/c/c.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +import "a/a.proto"; +import "google/protobuf/empty.proto"; + +package c; + +message C { + a.A a = 1; + google.protobuf.Empty empty = 2; +} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/wkt/proto/a/a.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/wkt/proto/a/a.proto new file mode 100644 index 0000000000..9a55caac03 --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/wkt/proto/a/a.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package a; + +import "b/b.proto"; +import "google/protobuf/empty.proto"; + +message A { + b.B b = 1; + google.protobuf.Empty empty = 2; +} diff --git a/private/buf/cmd/buf/testdata/workspace/success/v2/wkt/proto/b/b.proto b/private/buf/cmd/buf/testdata/workspace/success/v2/wkt/proto/b/b.proto new file mode 100644 index 0000000000..1b6b34425b --- /dev/null +++ b/private/buf/cmd/buf/testdata/workspace/success/v2/wkt/proto/b/b.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package b; + +import "google/protobuf/empty.proto"; + +message B { + google.protobuf.Empty empty = 1; +} + diff --git a/private/buf/cmd/buf/workspace_test.go b/private/buf/cmd/buf/workspace_test.go index 71c000d5b7..7206648d24 100644 --- a/private/buf/cmd/buf/workspace_test.go +++ b/private/buf/cmd/buf/workspace_test.go @@ -33,11 +33,11 @@ import ( func TestWorkspaceDir(t *testing.T) { // Directory paths contained within a workspace. t.Parallel() - // dir_buf_work contains a buf.work instead of a buf.work.yaml - // we want to make sure this still works for _, baseDirPath := range []string{ - "dir", - "dir_buf_work", + // TODO(doria): can we move `dir` and `dir_buf_work` into a directory `v1` for symmetry with `v2`? + "dir", // dir contains a v1 buf.work.yaml + "dir_buf_work", // dir_buf_work contains a v1 buf.work + "v2/dir", // v2/dir contains a v2 buf.yaml } { wd, err := osext.Getwd() require.NoError(t, err) @@ -134,36 +134,6 @@ func TestWorkspaceDir(t *testing.T) { "lint", filepath.Join("testdata", "workspace", "success", baseDirPath), ) - testRunStdout( - t, - nil, - 0, - ``, - "build", - filepath.Join("testdata", "workspace", "success", "breaking"), - ) - testRunStdout( - t, - nil, - 0, - filepath.FromSlash(`testdata/workspace/success/breaking/a/proto/a/v1/a.proto - testdata/workspace/success/breaking/other/proto/request.proto - testdata/workspace/success/breaking/proto/rpc.proto`), - "ls-files", - filepath.Join("testdata", "workspace", "success", "breaking"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/breaking/other/proto/request.proto:5:1:Previously present field "1" with name "name" on message "Request" was deleted. - testdata/workspace/success/breaking/proto/rpc.proto:8:5:Field "1" with name "request" on message "RPC" changed option "json_name" from "req" to "request". - testdata/workspace/success/breaking/proto/rpc.proto:8:21:Field "1" on message "RPC" changed name from "req" to "request".`), - "breaking", - filepath.Join("testdata", "workspace", "success", "breaking"), - "--against", - filepath.Join("testdata", "workspace", "success", baseDirPath), - ) testRunStdoutStderrNoWarn( t, nil, @@ -232,59 +202,278 @@ modules: } } +func TestWorkspaceBreaking(t *testing.T) { + t.Parallel() + for _, dirPaths := range []struct { + base string + against string + }{ + {base: "dir", against: "breaking"}, + {base: "dir_buf_work", against: "breaking"}, + {base: "v2/dir", against: "breaking"}, + {base: "v2/dir", against: "v2/breaking"}, + } { + testRunStdout( + t, + nil, + 0, + ``, + "build", + filepath.Join("testdata", "workspace", "success", dirPaths.against), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`testdata/workspace/success/`+dirPaths.against+`/a/proto/a/v1/a.proto + testdata/workspace/success/`+dirPaths.against+`/other/proto/request.proto + testdata/workspace/success/`+dirPaths.against+`/proto/rpc.proto`), + "ls-files", + filepath.Join("testdata", "workspace", "success", dirPaths.against), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`testdata/workspace/success/`+dirPaths.against+`/other/proto/request.proto:5:1:Previously present field "1" with name "name" on message "Request" was deleted. + testdata/workspace/success/`+dirPaths.against+`/proto/rpc.proto:8:5:Field "1" with name "request" on message "RPC" changed option "json_name" from "req" to "request". + testdata/workspace/success/`+dirPaths.against+`/proto/rpc.proto:8:21:Field "1" on message "RPC" changed name from "req" to "request".`), + "breaking", + filepath.Join("testdata", "workspace", "success", dirPaths.against), + "--against", + filepath.Join("testdata", "workspace", "success", dirPaths.base), + ) + } +} + func TestWorkspaceArchiveDir(t *testing.T) { // Archive that defines a workspace at the root of the archive. t.Parallel() - zipDir := createZipFromDir( - t, - filepath.Join("testdata", "workspace", "success", "dir"), - "archive.zip", - ) + for _, dirPath := range []string{ + "dir", + "v2/dir", + } { + zipDir := createZipFromDir( + t, + filepath.Join("testdata", "workspace", "success", dirPath), + "archive.zip", + ) + testRunStdout( + t, + nil, + 0, + ``, + "build", + filepath.Join(zipDir, "archive.zip#subdir=proto"), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`proto/rpc.proto`), + "ls-files", + filepath.Join(zipDir, "archive.zip#subdir=proto"), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`proto/rpc.proto:3:1:Files with package "example" must be within a directory "example" relative to root but were in directory ".". + proto/rpc.proto:3:1:Package name "example" should be suffixed with a correctly formed version, such as "example.v1".`), + "lint", + filepath.Join(zipDir, "archive.zip#subdir=proto"), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`proto/rpc.proto:3:1:Files with package "example" must be within a directory "example" relative to root but were in directory ".". + proto/rpc.proto:3:1:Package name "example" should be suffixed with a correctly formed version, such as "example.v1".`), + "lint", + filepath.Join(zipDir, "archive.zip#subdir=proto"), + "--path", + filepath.Join("proto", "rpc.proto"), + ) + } +} + +func TestWorkspaceNestedArchive(t *testing.T) { + // Archive that defines a workspace in a sub-directory to the root. + t.Parallel() + for _, dirPath := range []string{ + "nested", + "v2/nested", + } { + zipDir := createZipFromDir( + t, + filepath.Join("testdata", "workspace", "success", dirPath), + "archive.zip", + ) + testRunStdout( + t, + nil, + 0, + ``, + "build", + filepath.Join(zipDir, "archive.zip#subdir=proto/internal"), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`proto/internal/internal.proto`), + "ls-files", + filepath.Join(zipDir, "archive.zip#subdir=proto/internal"), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`proto/internal/internal.proto:3:1:Files with package "internal" must be within a directory "internal" relative to root but were in directory ".". + proto/internal/internal.proto:3:1:Package name "internal" should be suffixed with a correctly formed version, such as "internal.v1".`), + "lint", + filepath.Join(zipDir, "archive.zip#subdir=proto/internal"), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`proto/internal/internal.proto:3:1:Files with package "internal" must be within a directory "internal" relative to root but were in directory ".". + proto/internal/internal.proto:3:1:Package name "internal" should be suffixed with a correctly formed version, such as "internal.v1".`), + "lint", + filepath.Join(zipDir, "archive.zip#subdir=proto/internal"), + "--path", + filepath.Join("proto", "internal", "internal.proto"), + ) + } +} + +func TestWorkspaceDetached(t *testing.T) { + t.Parallel() + // The workspace doesn't include the 'proto' directory, so + // its contents aren't included in the workspace. + for _, dirPath := range []string{ + "detached", + "v2/detached", + } { + // In the pre-refactor, this was a successful call, as the workspace was still being discovered + // as the enclosing workspace, despite not pointing to the proto directory. In post-refactor + // we'd consider this a bug: you specified the proto directory, and no controlling workspace + // was discovered, therefore you build as if proto was the input directory, which results in + // request.proto not existing as an import. + testRunStdoutStderrNoWarn( + t, + nil, + bufctl.ExitCodeFileAnnotation, + ``, + `testdata/workspace/success/`+dirPath+`/proto/rpc.proto:5:8:stat request.proto: file does not exist`, + "build", + filepath.Join("testdata", "workspace", "success", dirPath, "proto"), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/proto/rpc.proto`), + "ls-files", + filepath.Join("testdata", "workspace", "success", dirPath, "proto"), + ) + // In the pre-refactor, this was a successful call, as the workspace was still being discovered + // as the enclosing workspace, despite not pointing to the proto directory. In post-refactor + // we'd consider this a bug: you specified the proto directory, and no controlling workspace + // was discovered, therefore you build as if proto was the input directory, which results in + // request.proto not existing as an import. + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + `testdata/workspace/success/`+dirPath+`/proto/rpc.proto:5:8:stat request.proto: file does not exist`, + "lint", + filepath.Join("testdata", "workspace", "success", dirPath, "proto"), + ) + testRunStdout( + t, + nil, + 0, + ``, + "build", + filepath.Join("testdata", "workspace", "success", dirPath, "other", "proto"), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/other/proto/request.proto`), + "ls-files", + filepath.Join("testdata", "workspace", "success", dirPath, "other", "proto"), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/other/proto/request.proto:3:1:Files with package "request" must be within a directory "request" relative to root but were in directory ".". + testdata/workspace/success/`+dirPath+`/other/proto/request.proto:3:1:Package name "request" should be suffixed with a correctly formed version, such as "request.v1".`), + "lint", + filepath.Join("testdata", "workspace", "success", dirPath, "other", "proto"), + ) + testRunStdout( + t, + nil, + 0, + ``, + "build", + filepath.Join("testdata", "workspace", "success", dirPath), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/other/proto/request.proto`), + "ls-files", + filepath.Join("testdata", "workspace", "success", dirPath), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/other/proto/request.proto:3:1:Files with package "request" must be within a directory "request" relative to root but were in directory ".". + testdata/workspace/success/`+dirPath+`/other/proto/request.proto:3:1:Package name "request" should be suffixed with a correctly formed version, such as "request.v1".`), + "lint", + filepath.Join("testdata", "workspace", "success", dirPath), + ) + } +} + +func TestWorkspaceNoModuleConfig(t *testing.T) { + // The workspace points to modules that don't contain a buf.yaml. + // + // This only tests for v1 workspaces, since in v2, we no longer have nested + // buf.yaml files for workspace modules. + t.Parallel() testRunStdout( t, nil, 0, ``, "build", - filepath.Join(zipDir, "archive.zip#subdir=proto"), + filepath.Join("testdata", "workspace", "success", "noconfig", "proto"), ) testRunStdout( t, nil, 0, - filepath.FromSlash(`proto/rpc.proto`), + filepath.FromSlash(`testdata/workspace/success/noconfig/proto/rpc.proto`), "ls-files", - filepath.Join(zipDir, "archive.zip#subdir=proto"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`proto/rpc.proto:3:1:Files with package "example" must be within a directory "example" relative to root but were in directory ".". - proto/rpc.proto:3:1:Package name "example" should be suffixed with a correctly formed version, such as "example.v1".`), - "lint", - filepath.Join(zipDir, "archive.zip#subdir=proto"), + filepath.Join("testdata", "workspace", "success", "noconfig", "proto"), ) testRunStdout( t, nil, bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`proto/rpc.proto:3:1:Files with package "example" must be within a directory "example" relative to root but were in directory ".". - proto/rpc.proto:3:1:Package name "example" should be suffixed with a correctly formed version, such as "example.v1".`), + filepath.FromSlash(`testdata/workspace/success/noconfig/proto/rpc.proto:3:1:Files with package "example" must be within a directory "example" relative to root but were in directory ".". + testdata/workspace/success/noconfig/proto/rpc.proto:3:1:Package name "example" should be suffixed with a correctly formed version, such as "example.v1".`), "lint", - filepath.Join(zipDir, "archive.zip#subdir=proto"), - "--path", - filepath.Join("proto", "rpc.proto"), - ) -} - -func TestWorkspaceNestedArchive(t *testing.T) { - // Archive that defines a workspace in a sub-directory to the root. - t.Parallel() - zipDir := createZipFromDir( - t, - filepath.Join("testdata", "workspace", "success", "nested"), - "archive.zip", + filepath.Join("testdata", "workspace", "success", "noconfig", "proto"), ) testRunStdout( t, @@ -292,211 +481,58 @@ func TestWorkspaceNestedArchive(t *testing.T) { 0, ``, "build", - filepath.Join(zipDir, "archive.zip#subdir=proto/internal"), + filepath.Join("testdata", "workspace", "success", "noconfig", "other", "proto"), ) testRunStdout( t, nil, 0, - filepath.FromSlash(`proto/internal/internal.proto`), + filepath.FromSlash(`testdata/workspace/success/noconfig/other/proto/request.proto`), "ls-files", - filepath.Join(zipDir, "archive.zip#subdir=proto/internal"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`proto/internal/internal.proto:3:1:Files with package "internal" must be within a directory "internal" relative to root but were in directory ".". - proto/internal/internal.proto:3:1:Package name "internal" should be suffixed with a correctly formed version, such as "internal.v1".`), - "lint", - filepath.Join(zipDir, "archive.zip#subdir=proto/internal"), + filepath.Join("testdata", "workspace", "success", "noconfig", "other", "proto"), ) testRunStdout( t, nil, bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`proto/internal/internal.proto:3:1:Files with package "internal" must be within a directory "internal" relative to root but were in directory ".". - proto/internal/internal.proto:3:1:Package name "internal" should be suffixed with a correctly formed version, such as "internal.v1".`), + filepath.FromSlash(`testdata/workspace/success/noconfig/other/proto/request.proto:3:1:Files with package "request" must be within a directory "request" relative to root but were in directory ".". + testdata/workspace/success/noconfig/other/proto/request.proto:3:1:Package name "request" should be suffixed with a correctly formed version, such as "request.v1".`), "lint", - filepath.Join(zipDir, "archive.zip#subdir=proto/internal"), - "--path", - filepath.Join("proto", "internal", "internal.proto"), + filepath.Join("testdata", "workspace", "success", "noconfig", "other", "proto"), ) } -func TestWorkspaceDetached(t *testing.T) { - // The workspace doesn't include the 'proto' directory, so - // its contents aren't included in the workspace. +func TestWorkspaceWithLock(t *testing.T) { + // The workspace points to a module that includes a buf.lock, but + // the listed dependency is defined in the workspace so the module + // cache is unused. + // + // This only tests for v1 workspaces, since in v2, we no longer have nested + // buf.lock files for workspace modules and this module would already be excluded + // from the workspace-level buf.lock. t.Parallel() - // In the pre-refactor, this was a successful call, as the workspace was still being discovered - // as the enclosing workspace, despite not pointing to the proto directory. In post-refactor - // we'd consider this a bug: you specified the proto directory, and no controlling workspace - // was discovered, therefore you build as if proto was the input directory, which results in - // request.proto not existing as an import. - testRunStdoutStderrNoWarn( + testRunStdout( t, nil, - bufctl.ExitCodeFileAnnotation, + 0, ``, - `testdata/workspace/success/detached/proto/rpc.proto:5:8:stat request.proto: file does not exist`, "build", - filepath.Join("testdata", "workspace", "success", "detached", "proto"), + filepath.Join("testdata", "workspace", "success", "lock", "a"), ) testRunStdout( t, nil, 0, - filepath.FromSlash(`testdata/workspace/success/detached/proto/rpc.proto`), + filepath.FromSlash(`testdata/workspace/success/lock/a/a.proto`), "ls-files", - filepath.Join("testdata", "workspace", "success", "detached", "proto"), + filepath.Join("testdata", "workspace", "success", "lock", "a"), ) - // In the pre-refactor, this was a successful call, as the workspace was still being discovered - // as the enclosing workspace, despite not pointing to the proto directory. In post-refactor - // we'd consider this a bug: you specified the proto directory, and no controlling workspace - // was discovered, therefore you build as if proto was the input directory, which results in - // request.proto not existing as an import. testRunStdout( t, nil, bufctl.ExitCodeFileAnnotation, - `testdata/workspace/success/detached/proto/rpc.proto:5:8:stat request.proto: file does not exist`, - "lint", - filepath.Join("testdata", "workspace", "success", "detached", "proto"), - ) - testRunStdout( - t, - nil, - 0, - ``, - "build", - filepath.Join("testdata", "workspace", "success", "detached", "other", "proto"), - ) - testRunStdout( - t, - nil, - 0, - filepath.FromSlash(`testdata/workspace/success/detached/other/proto/request.proto`), - "ls-files", - filepath.Join("testdata", "workspace", "success", "detached", "other", "proto"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/detached/other/proto/request.proto:3:1:Files with package "request" must be within a directory "request" relative to root but were in directory ".". - testdata/workspace/success/detached/other/proto/request.proto:3:1:Package name "request" should be suffixed with a correctly formed version, such as "request.v1".`), - "lint", - filepath.Join("testdata", "workspace", "success", "detached", "other", "proto"), - ) - testRunStdout( - t, - nil, - 0, - ``, - "build", - filepath.Join("testdata", "workspace", "success", "detached"), - ) - testRunStdout( - t, - nil, - 0, - filepath.FromSlash(`testdata/workspace/success/detached/other/proto/request.proto`), - "ls-files", - filepath.Join("testdata", "workspace", "success", "detached"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/detached/other/proto/request.proto:3:1:Files with package "request" must be within a directory "request" relative to root but were in directory ".". - testdata/workspace/success/detached/other/proto/request.proto:3:1:Package name "request" should be suffixed with a correctly formed version, such as "request.v1".`), - "lint", - filepath.Join("testdata", "workspace", "success", "detached"), - ) -} - -func TestWorkspaceNoModuleConfig(t *testing.T) { - // The workspace points to modules that don't contain a buf.yaml. - t.Parallel() - testRunStdout( - t, - nil, - 0, - ``, - "build", - filepath.Join("testdata", "workspace", "success", "noconfig", "proto"), - ) - testRunStdout( - t, - nil, - 0, - filepath.FromSlash(`testdata/workspace/success/noconfig/proto/rpc.proto`), - "ls-files", - filepath.Join("testdata", "workspace", "success", "noconfig", "proto"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/noconfig/proto/rpc.proto:3:1:Files with package "example" must be within a directory "example" relative to root but were in directory ".". - testdata/workspace/success/noconfig/proto/rpc.proto:3:1:Package name "example" should be suffixed with a correctly formed version, such as "example.v1".`), - "lint", - filepath.Join("testdata", "workspace", "success", "noconfig", "proto"), - ) - testRunStdout( - t, - nil, - 0, - ``, - "build", - filepath.Join("testdata", "workspace", "success", "noconfig", "other", "proto"), - ) - testRunStdout( - t, - nil, - 0, - filepath.FromSlash(`testdata/workspace/success/noconfig/other/proto/request.proto`), - "ls-files", - filepath.Join("testdata", "workspace", "success", "noconfig", "other", "proto"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/noconfig/other/proto/request.proto:3:1:Files with package "request" must be within a directory "request" relative to root but were in directory ".". - testdata/workspace/success/noconfig/other/proto/request.proto:3:1:Package name "request" should be suffixed with a correctly formed version, such as "request.v1".`), - "lint", - filepath.Join("testdata", "workspace", "success", "noconfig", "other", "proto"), - ) -} - -func TestWorkspaceWithLock(t *testing.T) { - // The workspace points to a module that includes a buf.lock, but - // the listed dependency is defined in the workspace so the module - // cache is unused. - t.Parallel() - testRunStdout( - t, - nil, - 0, - ``, - "build", - filepath.Join("testdata", "workspace", "success", "lock", "a"), - ) - testRunStdout( - t, - nil, - 0, - filepath.FromSlash(`testdata/workspace/success/lock/a/a.proto`), - "ls-files", - filepath.Join("testdata", "workspace", "success", "lock", "a"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/lock/a/a.proto:3:1:Files with package "a" must be within a directory "a" relative to root but were in directory ".". - testdata/workspace/success/lock/a/a.proto:3:1:Package name "a" should be suffixed with a correctly formed version, such as "a.v1".`), + filepath.FromSlash(`testdata/workspace/success/lock/a/a.proto:3:1:Files with package "a" must be within a directory "a" relative to root but were in directory ".". + testdata/workspace/success/lock/a/a.proto:3:1:Package name "a" should be suffixed with a correctly formed version, such as "a.v1".`), "lint", filepath.Join("testdata", "workspace", "success", "lock", "a"), ) @@ -528,268 +564,285 @@ func TestWorkspaceWithLock(t *testing.T) { } func TestWorkspaceWithTransitiveDependencies(t *testing.T) { + t.Parallel() // The workspace points to a module that includes transitive // dependencies (i.e. a depends on b, and b depends on c). - t.Parallel() - testRunStdout( - t, - nil, - 0, - ``, - "build", - filepath.Join("testdata", "workspace", "success", "transitive", "proto"), - ) - testRunStdout( - t, - nil, - 0, - filepath.FromSlash(`testdata/workspace/success/transitive/proto/a.proto`), - "ls-files", - filepath.Join("testdata", "workspace", "success", "transitive", "proto"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/transitive/proto/a.proto:3:1:Files with package "a" must be within a directory "a" relative to root but were in directory ".". - testdata/workspace/success/transitive/proto/a.proto:3:1:Package name "a" should be suffixed with a correctly formed version, such as "a.v1".`), - "lint", - filepath.Join("testdata", "workspace", "success", "transitive", "proto"), - ) - testRunStdout( - t, - nil, - 0, - ``, - "build", - filepath.Join("testdata", "workspace", "success", "transitive", "private", "proto"), - ) - testRunStdout( - t, - nil, - 0, - filepath.FromSlash(`testdata/workspace/success/transitive/private/proto/b.proto`), - "ls-files", - filepath.Join("testdata", "workspace", "success", "transitive", "private", "proto"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/transitive/private/proto/b.proto:3:1:Files with package "b" must be within a directory "b" relative to root but were in directory ".". - testdata/workspace/success/transitive/private/proto/b.proto:3:1:Package name "b" should be suffixed with a correctly formed version, such as "b.v1".`), - "lint", - filepath.Join("testdata", "workspace", "success", "transitive", "private", "proto"), - ) - testRunStdout( - t, - nil, - 0, - ``, - "build", - filepath.Join("testdata", "workspace", "success", "transitive", "other", "proto"), - ) - testRunStdout( - t, - nil, - 0, - filepath.FromSlash(`testdata/workspace/success/transitive/other/proto/c.proto`), - "ls-files", - filepath.Join("testdata", "workspace", "success", "transitive", "other", "proto"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/transitive/other/proto/c.proto:3:1:Files with package "c" must be within a directory "c" relative to root but were in directory ".". - testdata/workspace/success/transitive/other/proto/c.proto:3:1:Package name "c" should be suffixed with a correctly formed version, such as "c.v1".`), - "lint", - filepath.Join("testdata", "workspace", "success", "transitive", "other", "proto"), - ) - testRunStdout( - t, - nil, - 0, - ``, - "build", - filepath.Join("testdata", "workspace", "success", "transitive"), - ) - testRunStdout( - t, - nil, - 0, - filepath.FromSlash(`testdata/workspace/success/transitive/other/proto/c.proto - testdata/workspace/success/transitive/private/proto/b.proto - testdata/workspace/success/transitive/proto/a.proto`), - "ls-files", - filepath.Join("testdata", "workspace", "success", "transitive"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/transitive/other/proto/c.proto:3:1:Files with package "c" must be within a directory "c" relative to root but were in directory ".". - testdata/workspace/success/transitive/other/proto/c.proto:3:1:Package name "c" should be suffixed with a correctly formed version, such as "c.v1". - testdata/workspace/success/transitive/private/proto/b.proto:3:1:Files with package "b" must be within a directory "b" relative to root but were in directory ".". - testdata/workspace/success/transitive/private/proto/b.proto:3:1:Package name "b" should be suffixed with a correctly formed version, such as "b.v1". - testdata/workspace/success/transitive/proto/a.proto:3:1:Files with package "a" must be within a directory "a" relative to root but were in directory ".". - testdata/workspace/success/transitive/proto/a.proto:3:1:Package name "a" should be suffixed with a correctly formed version, such as "a.v1".`), - "lint", - filepath.Join("testdata", "workspace", "success", "transitive"), - ) + for _, dirPath := range []string{ + "transitive", + "v2/transitive", + } { + testRunStdout( + t, + nil, + 0, + ``, + "build", + filepath.Join("testdata", "workspace", "success", dirPath, "proto"), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/proto/a.proto`), + "ls-files", + filepath.Join("testdata", "workspace", "success", dirPath, "proto"), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/proto/a.proto:3:1:Files with package "a" must be within a directory "a" relative to root but were in directory ".". + testdata/workspace/success/`+dirPath+`/proto/a.proto:3:1:Package name "a" should be suffixed with a correctly formed version, such as "a.v1".`), + "lint", + filepath.Join("testdata", "workspace", "success", dirPath, "proto"), + ) + testRunStdout( + t, + nil, + 0, + ``, + "build", + filepath.Join("testdata", "workspace", "success", dirPath, "private", "proto"), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/private/proto/b.proto`), + "ls-files", + filepath.Join("testdata", "workspace", "success", dirPath, "private", "proto"), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/private/proto/b.proto:3:1:Files with package "b" must be within a directory "b" relative to root but were in directory ".". + testdata/workspace/success/`+dirPath+`/private/proto/b.proto:3:1:Package name "b" should be suffixed with a correctly formed version, such as "b.v1".`), + "lint", + filepath.Join("testdata", "workspace", "success", dirPath, "private", "proto"), + ) + testRunStdout( + t, + nil, + 0, + ``, + "build", + filepath.Join("testdata", "workspace", "success", dirPath, "other", "proto"), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/other/proto/c.proto`), + "ls-files", + filepath.Join("testdata", "workspace", "success", dirPath, "other", "proto"), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/other/proto/c.proto:3:1:Files with package "c" must be within a directory "c" relative to root but were in directory ".". + testdata/workspace/success/`+dirPath+`/other/proto/c.proto:3:1:Package name "c" should be suffixed with a correctly formed version, such as "c.v1".`), + "lint", + filepath.Join("testdata", "workspace", "success", dirPath, "other", "proto"), + ) + testRunStdout( + t, + nil, + 0, + ``, + "build", + filepath.Join("testdata", "workspace", "success", dirPath), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/other/proto/c.proto + testdata/workspace/success/`+dirPath+`/private/proto/b.proto + testdata/workspace/success/`+dirPath+`/proto/a.proto`), + "ls-files", + filepath.Join("testdata", "workspace", "success", dirPath), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/other/proto/c.proto:3:1:Files with package "c" must be within a directory "c" relative to root but were in directory ".". + testdata/workspace/success/`+dirPath+`/other/proto/c.proto:3:1:Package name "c" should be suffixed with a correctly formed version, such as "c.v1". + testdata/workspace/success/`+dirPath+`/private/proto/b.proto:3:1:Files with package "b" must be within a directory "b" relative to root but were in directory ".". + testdata/workspace/success/`+dirPath+`/private/proto/b.proto:3:1:Package name "b" should be suffixed with a correctly formed version, such as "b.v1". + testdata/workspace/success/`+dirPath+`/proto/a.proto:3:1:Files with package "a" must be within a directory "a" relative to root but were in directory ".". + testdata/workspace/success/`+dirPath+`/proto/a.proto:3:1:Package name "a" should be suffixed with a correctly formed version, such as "a.v1".`), + "lint", + filepath.Join("testdata", "workspace", "success", dirPath), + ) + } } func TestWorkspaceWithDiamondDependency(t *testing.T) { + t.Parallel() // The workspace points to a module that includes a diamond // dependency (i.e. a depends on b and c, and b depends on c). - t.Parallel() - testRunStdout( - t, - nil, - 0, - ``, - "build", - filepath.Join("testdata", "workspace", "success", "diamond", "proto"), - ) - testRunStdout( - t, - nil, - 0, - filepath.FromSlash(`testdata/workspace/success/diamond/proto/a.proto`), - "ls-files", - filepath.Join("testdata", "workspace", "success", "diamond", "proto"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/diamond/proto/a.proto:3:1:Files with package "a" must be within a directory "a" relative to root but were in directory ".". - testdata/workspace/success/diamond/proto/a.proto:3:1:Package name "a" should be suffixed with a correctly formed version, such as "a.v1".`), - "lint", - filepath.Join("testdata", "workspace", "success", "diamond", "proto"), - ) - testRunStdout( - t, - nil, - 0, - ``, - "build", - filepath.Join("testdata", "workspace", "success", "diamond", "private", "proto"), - ) - testRunStdout( - t, - nil, - 0, - filepath.FromSlash(`testdata/workspace/success/diamond/private/proto/b.proto`), - "ls-files", - filepath.Join("testdata", "workspace", "success", "diamond", "private", "proto"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/diamond/private/proto/b.proto:3:1:Files with package "b" must be within a directory "b" relative to root but were in directory ".". - testdata/workspace/success/diamond/private/proto/b.proto:3:1:Package name "b" should be suffixed with a correctly formed version, such as "b.v1".`), - "lint", - filepath.Join("testdata", "workspace", "success", "diamond", "private", "proto"), - ) - testRunStdout( - t, - nil, - 0, - ``, - "build", - filepath.Join("testdata", "workspace", "success", "diamond", "other", "proto"), - ) - testRunStdout( - t, - nil, - 0, - filepath.FromSlash(`testdata/workspace/success/diamond/other/proto/c.proto`), - "ls-files", - filepath.Join("testdata", "workspace", "success", "diamond", "other", "proto"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/diamond/other/proto/c.proto:3:1:Files with package "c" must be within a directory "c" relative to root but were in directory ".". - testdata/workspace/success/diamond/other/proto/c.proto:3:1:Package name "c" should be suffixed with a correctly formed version, such as "c.v1".`), - "lint", - filepath.Join("testdata", "workspace", "success", "diamond", "other", "proto"), - ) + for _, dirPath := range []string{ + "diamond", + "v2/diamond", + } { + testRunStdout( + t, + nil, + 0, + ``, + "build", + filepath.Join("testdata", "workspace", "success", dirPath, "proto"), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/proto/a.proto`), + "ls-files", + filepath.Join("testdata", "workspace", "success", dirPath, "proto"), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/proto/a.proto:3:1:Files with package "a" must be within a directory "a" relative to root but were in directory ".". + testdata/workspace/success/`+dirPath+`/proto/a.proto:3:1:Package name "a" should be suffixed with a correctly formed version, such as "a.v1".`), + "lint", + filepath.Join("testdata", "workspace", "success", dirPath, "proto"), + ) + testRunStdout( + t, + nil, + 0, + ``, + "build", + filepath.Join("testdata", "workspace", "success", dirPath, "private", "proto"), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/private/proto/b.proto`), + "ls-files", + filepath.Join("testdata", "workspace", "success", dirPath, "private", "proto"), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/private/proto/b.proto:3:1:Files with package "b" must be within a directory "b" relative to root but were in directory ".". + testdata/workspace/success/`+dirPath+`/private/proto/b.proto:3:1:Package name "b" should be suffixed with a correctly formed version, such as "b.v1".`), + "lint", + filepath.Join("testdata", "workspace", "success", dirPath, "private", "proto"), + ) + testRunStdout( + t, + nil, + 0, + ``, + "build", + filepath.Join("testdata", "workspace", "success", dirPath, "other", "proto"), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/other/proto/c.proto`), + "ls-files", + filepath.Join("testdata", "workspace", "success", dirPath, "other", "proto"), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/other/proto/c.proto:3:1:Files with package "c" must be within a directory "c" relative to root but were in directory ".". + testdata/workspace/success/`+dirPath+`/other/proto/c.proto:3:1:Package name "c" should be suffixed with a correctly formed version, such as "c.v1".`), + "lint", + filepath.Join("testdata", "workspace", "success", dirPath, "other", "proto"), + ) + } } func TestWorkspaceWKT(t *testing.T) { + t.Parallel() // The workspace includes multiple images that import the same // well-known type (empty.proto). - t.Parallel() - testRunStdout( - t, - nil, - 0, - ``, - "build", - filepath.Join("testdata", "workspace", "success", "wkt", "other", "proto"), - ) - testRunStdout( - t, - nil, - 0, - filepath.FromSlash(`testdata/workspace/success/wkt/other/proto/c/c.proto`), - "ls-files", - filepath.Join("testdata", "workspace", "success", "wkt", "other", "proto"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/wkt/other/proto/c/c.proto:6:1:Package name "c" should be suffixed with a correctly formed version, such as "c.v1".`), - "lint", - filepath.Join("testdata", "workspace", "success", "wkt", "other", "proto"), - ) - testRunStdout( - t, - nil, - 0, - ``, - "build", - filepath.Join("testdata", "workspace", "success", "wkt"), - ) - testRunStdout( - t, - nil, - 0, - filepath.FromSlash(`testdata/workspace/success/wkt/other/proto/c/c.proto - testdata/workspace/success/wkt/proto/a/a.proto - testdata/workspace/success/wkt/proto/b/b.proto`), - "ls-files", - filepath.Join("testdata", "workspace", "success", "wkt"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/wkt/other/proto/c/c.proto:6:1:Package name "c" should be suffixed with a correctly formed version, such as "c.v1". - testdata/workspace/success/wkt/proto/a/a.proto:3:1:Package name "a" should be suffixed with a correctly formed version, such as "a.v1". - testdata/workspace/success/wkt/proto/b/b.proto:3:1:Package name "b" should be suffixed with a correctly formed version, such as "b.v1".`), - "lint", - filepath.Join("testdata", "workspace", "success", "wkt"), - ) - testRunStdout( - t, - nil, - 0, - ``, - "breaking", - filepath.Join("testdata", "workspace", "success", "wkt"), - "--against", - filepath.Join("testdata", "workspace", "success", "wkt"), - ) + for _, dirPath := range []string{ + "wkt", + "v2/wkt", + } { + testRunStdout( + t, + nil, + 0, + ``, + "build", + filepath.Join("testdata", "workspace", "success", dirPath, "other", "proto"), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/other/proto/c/c.proto`), + "ls-files", + filepath.Join("testdata", "workspace", "success", dirPath, "other", "proto"), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/other/proto/c/c.proto:6:1:Package name "c" should be suffixed with a correctly formed version, such as "c.v1".`), + "lint", + filepath.Join("testdata", "workspace", "success", dirPath, "other", "proto"), + ) + testRunStdout( + t, + nil, + 0, + ``, + "build", + filepath.Join("testdata", "workspace", "success", dirPath), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/other/proto/c/c.proto + testdata/workspace/success/`+dirPath+`/proto/a/a.proto + testdata/workspace/success/`+dirPath+`/proto/b/b.proto`), + "ls-files", + filepath.Join("testdata", "workspace", "success", dirPath), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`testdata/workspace/success/`+dirPath+`/other/proto/c/c.proto:6:1:Package name "c" should be suffixed with a correctly formed version, such as "c.v1". + testdata/workspace/success/`+dirPath+`/proto/a/a.proto:3:1:Package name "a" should be suffixed with a correctly formed version, such as "a.v1". + testdata/workspace/success/`+dirPath+`/proto/b/b.proto:3:1:Package name "b" should be suffixed with a correctly formed version, such as "b.v1".`), + "lint", + filepath.Join("testdata", "workspace", "success", dirPath), + ) + testRunStdout( + t, + nil, + 0, + ``, + "breaking", + filepath.Join("testdata", "workspace", "success", dirPath), + "--against", + filepath.Join("testdata", "workspace", "success", dirPath), + ) + } } func TestWorkspaceRoots(t *testing.T) { // Workspaces should support modules with multiple roots specified in a v1beta1 buf.yaml. + // This is only tested with v1 workspaces, since v2 workspaces does not support individual + // buf.yaml configurations. t.Parallel() testRunStdout( t, @@ -873,6 +926,53 @@ testdata/workspace/success/roots/module2/root3/d/d.proto:3:1:Package name "d" sh ) } +func TestWorkspaceProtoFile(t *testing.T) { + t.Parallel() + // The ProtoFileRef is only accepted for lint commands, currently + // dir_buf_work contains a buf.work instead of a buf.work.yaml + // we want to make sure this still works + for _, baseDirPath := range []string{ + "dir", + "dir_buf_work", + "v2/dir", + } { + wd, err := osext.Getwd() + require.NoError(t, err) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash( + `testdata/workspace/success/`+baseDirPath+`/proto/rpc.proto:3:1:Files with package "example" must be within a directory "example" relative to root but were in directory ".". + testdata/workspace/success/`+baseDirPath+`/proto/rpc.proto:3:1:Package name "example" should be suffixed with a correctly formed version, such as "example.v1".`, + ), + "lint", + filepath.Join("testdata", "workspace", "success", baseDirPath, "proto", "rpc.proto"), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`testdata/workspace/success/`+baseDirPath+`/other/proto/request.proto:3:1:Files with package "request" must be within a directory "request" relative to root but were in directory ".". + testdata/workspace/success/`+baseDirPath+`/other/proto/request.proto:3:1:Package name "request" should be suffixed with a correctly formed version, such as "request.v1".`, + ), + "lint", + filepath.Join("testdata", "workspace", "success", baseDirPath, "other", "proto", "request.proto"), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash( + fmt.Sprintf(`%s/testdata/workspace/success/`+baseDirPath+`/other/proto/request.proto:3:1:Files with package "request" must be within a directory "request" relative to root but were in directory ".". + %s/testdata/workspace/success/`+baseDirPath+`/other/proto/request.proto:3:1:Package name "request" should be suffixed with a correctly formed version, such as "request.v1".`, wd, wd), + ), + "lint", + filepath.Join(wd, "testdata", "workspace", "success", baseDirPath, "other", "proto", "request.proto"), + ) + } +} + func TestWorkspaceBreakingFail(t *testing.T) { t.Parallel() // The two workspaces define a different number of @@ -896,6 +996,17 @@ func TestWorkspaceBreakingFail(t *testing.T) { "--against", filepath.Join("testdata", "workspace", "success", "breaking"), ) + testRunStdoutStderrNoWarn( + t, + nil, + 1, + ``, + `Failure: input contained 1 images, whereas against contained 3 images`, + "breaking", + filepath.Join("testdata", "workspace", "fail", "breaking"), + "--against", + filepath.Join("testdata", "workspace", "success", "v2", "breaking"), + ) } func TestWorkspaceDuplicateFail(t *testing.T) { @@ -910,6 +1021,15 @@ func TestWorkspaceDuplicateFail(t *testing.T) { "build", filepath.Join("testdata", "workspace", "fail", "duplicate"), ) + testRunStdoutStderrNoWarn( + t, + nil, + 1, + ``, + filepath.FromSlash(`Failure: foo.proto exists in multiple locations: testdata/workspace/fail/v2/duplicate/other/proto/foo.proto testdata/workspace/fail/v2/duplicate/proto/foo.proto`), + "build", + filepath.Join("testdata", "workspace", "fail", "v2", "duplicate"), + ) } func TestWorkspaceDuplicateFailSpecificModule(t *testing.T) { @@ -923,6 +1043,15 @@ func TestWorkspaceDuplicateFailSpecificModule(t *testing.T) { "build", filepath.Join("testdata", "workspace", "fail", "duplicate", "proto"), ) + testRunStdoutStderrNoWarn( + t, + nil, + 1, + ``, + filepath.FromSlash(`Failure: foo.proto exists in multiple locations: testdata/workspace/fail/v2/duplicate/other/proto/foo.proto testdata/workspace/fail/v2/duplicate/proto/foo.proto`), + "build", + filepath.Join("testdata", "workspace", "fail", "v2", "duplicate", "proto"), + ) } func TestWorkspaceNotExistFail(t *testing.T) { @@ -937,6 +1066,15 @@ func TestWorkspaceNotExistFail(t *testing.T) { "build", filepath.Join("testdata", "workspace", "fail", "notexist"), ) + testRunStdoutStderrNoWarn( + t, + nil, + 1, + ``, + filepath.FromSlash(`Failure: module "notexist" had no .proto files`), + "build", + filepath.Join("testdata", "workspace", "fail", "v2", "notexist"), + ) } func TestWorkspaceJumpContextFail(t *testing.T) { @@ -951,6 +1089,15 @@ func TestWorkspaceJumpContextFail(t *testing.T) { "build", filepath.Join("testdata", "workspace", "fail", "jumpcontext"), ) + testRunStdoutStderrNoWarn( + t, + nil, + 1, + ``, + filepath.FromSlash(`Failure: decode testdata/workspace/fail/v2/jumpcontext/buf.yaml: invalid module directory: ../breaking/other/proto: is outside the context directory`), + "build", + filepath.Join("testdata", "workspace", "fail", "v2", "jumpcontext"), + ) } func TestWorkspaceDirOverlapFail(t *testing.T) { @@ -1049,6 +1196,17 @@ func TestWorkspaceWithWorkspacePathFail(t *testing.T) { "--path", filepath.Join("testdata", "workspace", "success", "dir"), ) + testRunStdoutStderrNoWarn( + t, + nil, + 1, + ``, + `Failure: given input is equal to a value of --path - this has no effect and is disallowed`, + "lint", + filepath.Join("testdata", "workspace", "success", "v2", "dir"), + "--path", + filepath.Join("testdata", "workspace", "success", "v2", "dir"), + ) } func TestWorkspaceWithWorkspaceExcludePathFail(t *testing.T) { @@ -1064,6 +1222,17 @@ func TestWorkspaceWithWorkspaceExcludePathFail(t *testing.T) { "--exclude-path", filepath.Join("testdata", "workspace", "success", "dir"), ) + testRunStdoutStderrNoWarn( + t, + nil, + 1, + ``, + `Failure: given input is equal to a value of --exclude-path - this would exclude everything`, + "lint", + filepath.Join("testdata", "workspace", "success", "v2", "dir"), + "--exclude-path", + filepath.Join("testdata", "workspace", "success", "v2", "dir"), + ) } func TestWorkspaceWithWorkspaceDirectoryPathFail(t *testing.T) { @@ -1080,6 +1249,17 @@ func TestWorkspaceWithWorkspaceDirectoryPathFail(t *testing.T) { "--path", filepath.Join("testdata", "workspace", "success", "dir", "proto"), ) + testRunStdoutStderrNoWarn( + t, + nil, + 1, + ``, + `Failure: module "proto" was specified with --path - specify this module path directly as an input`, + "lint", + filepath.Join("testdata", "workspace", "success", "v2", "dir"), + "--path", + filepath.Join("testdata", "workspace", "success", "v2", "dir", "proto"), + ) } func TestWorkspaceWithInvalidWorkspaceDirectoryPathFail(t *testing.T) { @@ -1097,6 +1277,17 @@ func TestWorkspaceWithInvalidWorkspaceDirectoryPathFail(t *testing.T) { "--path", filepath.Join("testdata", "workspace", "success", "dir", "notexist"), ) + testRunStdoutStderrNoWarn( + t, + nil, + 1, + ``, + `Failure: `+bufmodule.ErrNoTargetProtoFiles.Error(), + "lint", + filepath.Join("testdata", "workspace", "success", "v2", "dir"), + "--path", + filepath.Join("testdata", "workspace", "success", "v2", "dir", "notexist"), + ) } func TestWorkspaceWithInvalidDirPathFail(t *testing.T) { @@ -1114,6 +1305,17 @@ func TestWorkspaceWithInvalidDirPathFail(t *testing.T) { "--path", filepath.Join("testdata", "workspace", "success", "detached", "proto", "notexist"), ) + testRunStdoutStderrNoWarn( + t, + nil, + 1, + ``, + `Failure: `+bufmodule.ErrNoTargetProtoFiles.Error(), + "lint", + filepath.Join("testdata", "workspace", "success", "v2", "detached", "proto"), + "--path", + filepath.Join("testdata", "workspace", "success", "v2", "detached", "proto", "notexist"), + ) } func TestWorkspaceWithInvalidArchivePathFail(t *testing.T) { @@ -1134,6 +1336,22 @@ func TestWorkspaceWithInvalidArchivePathFail(t *testing.T) { "--path", filepath.Join("proto", "notexist"), ) + zipDir = createZipFromDir( + t, + filepath.Join("testdata", "workspace", "success", "v2", "dir"), + "archive.zip", + ) + testRunStdoutStderrNoWarn( + t, + nil, + 1, + ``, + `Failure: `+bufmodule.ErrNoTargetProtoFiles.Error(), + "lint", + filepath.Join(zipDir, "archive.zip#subdir=proto"), + "--path", + filepath.Join("proto", "notexist"), + ) } func TestWorkspaceWithInvalidArchiveAbsolutePathFail(t *testing.T) { @@ -1159,6 +1377,25 @@ func TestWorkspaceWithInvalidArchiveAbsolutePathFail(t *testing.T) { "--path", filepath.Join(wd, "proto", "rpc.proto"), ) + zipDir = createZipFromDir( + t, + filepath.Join("testdata", "workspace", "success", "v2", "dir"), + "archive.zip", + ) + testRunStdoutStderrNoWarn( + t, + nil, + 1, + ``, + filepath.FromSlash(fmt.Sprintf( + `Failure: %s/proto/rpc.proto: absolute paths cannot be used for this input type`, + wd, + )), + "lint", + filepath.Join(zipDir, "archive.zip#subdir=proto"), + "--path", + filepath.Join(wd, "proto", "rpc.proto"), + ) } func createZipFromDir(t *testing.T, rootPath string, archiveName string) string { @@ -1205,65 +1442,3 @@ func createZipFromDir(t *testing.T, rootPath string, archiveName string) string require.NoError(t, err) return zipDir } - -func TestWorkspaceProtoFile(t *testing.T) { - t.Parallel() - // The ProtoFileRef is only accepted for lint commands, currently - // dir_buf_work contains a buf.work instead of a buf.work.yaml - // we want to make sure this still works - for _, baseDirPath := range []string{ - "dir", - "dir_buf_work", - } { - wd, err := osext.Getwd() - require.NoError(t, err) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash( - `testdata/workspace/success/`+baseDirPath+`/proto/rpc.proto:3:1:Files with package "example" must be within a directory "example" relative to root but were in directory ".". - testdata/workspace/success/`+baseDirPath+`/proto/rpc.proto:3:1:Package name "example" should be suffixed with a correctly formed version, such as "example.v1".`, - ), - "lint", - filepath.Join("testdata", "workspace", "success", baseDirPath, "proto", "rpc.proto"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/`+baseDirPath+`/other/proto/request.proto:3:1:Files with package "request" must be within a directory "request" relative to root but were in directory ".". - testdata/workspace/success/`+baseDirPath+`/other/proto/request.proto:3:1:Package name "request" should be suffixed with a correctly formed version, such as "request.v1".`, - ), - "lint", - filepath.Join("testdata", "workspace", "success", baseDirPath, "other", "proto", "request.proto"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash( - fmt.Sprintf(`%s/testdata/workspace/success/`+baseDirPath+`/other/proto/request.proto:3:1:Files with package "request" must be within a directory "request" relative to root but were in directory ".". - %s/testdata/workspace/success/`+baseDirPath+`/other/proto/request.proto:3:1:Package name "request" should be suffixed with a correctly formed version, such as "request.v1".`, wd, wd), - ), - "lint", - filepath.Join(wd, "testdata", "workspace", "success", baseDirPath, "other", "proto", "request.proto"), - ) - } - testRunStdout( - t, - nil, - 0, - "", // We are not expecting an output for stdout for a successful build - "build", - filepath.Join("testdata", "workspace", "success", "protofileref", "another", "foo", "foo.proto"), - ) - testRunStdout( - t, - nil, - bufctl.ExitCodeFileAnnotation, - filepath.FromSlash(`testdata/workspace/success/protofileref/another/foo/foo.proto:3:1:Package name "foo" should be suffixed with a correctly formed version, such as "foo.v1".`), - "lint", - filepath.Join("testdata", "workspace", "success", "protofileref", "another", "foo", "foo.proto"), - ) -} diff --git a/private/buf/cmd/buf/workspace_unix_test.go b/private/buf/cmd/buf/workspace_unix_test.go index acb0fb9020..7f2bc3a8ba 100644 --- a/private/buf/cmd/buf/workspace_unix_test.go +++ b/private/buf/cmd/buf/workspace_unix_test.go @@ -36,6 +36,15 @@ func TestWorkspaceSymlinkFail(t *testing.T) { "build", filepath.Join("testdata", "workspace", "fail", "symlink"), ) + testRunStdoutStderrNoWarn( + t, + nil, + bufctl.ExitCodeFileAnnotation, + ``, + filepath.FromSlash(`testdata/workspace/fail/v2/symlink/b/b.proto:5:8:stat c.proto: file does not exist`), + "build", + filepath.Join("testdata", "workspace", "fail", "v2", "symlink"), + ) } func TestWorkspaceSymlink(t *testing.T) { @@ -72,11 +81,42 @@ func TestWorkspaceSymlink(t *testing.T) { "lint", filepath.Join("testdata", "workspace", "success", "symlink"), ) + testRunStdout( + t, + nil, + 0, + ``, + "build", + filepath.Join("testdata", "workspace", "success", "v2", "symlink"), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`testdata/workspace/success/v2/symlink/a/a.proto + testdata/workspace/success/v2/symlink/b/b.proto + testdata/workspace/success/v2/symlink/c/c.proto`), + "ls-files", + filepath.Join("testdata", "workspace", "success", "v2", "symlink"), + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`testdata/workspace/success/v2/symlink/a/a.proto:3:1:Files with package "a" must be within a directory "a" relative to root but were in directory ".". + testdata/workspace/success/v2/symlink/a/a.proto:3:1:Package name "a" should be suffixed with a correctly formed version, such as "a.v1". + testdata/workspace/success/v2/symlink/b/b.proto:3:1:Files with package "b" must be within a directory "b" relative to root but were in directory ".". + testdata/workspace/success/v2/symlink/b/b.proto:3:1:Package name "b" should be suffixed with a correctly formed version, such as "b.v1". + testdata/workspace/success/v2/symlink/c/c.proto:3:1:Files with package "c" must be within a directory "c" relative to root but were in directory ".". + testdata/workspace/success/v2/symlink/c/c.proto:3:1:Package name "c" should be suffixed with a correctly formed version, such as "c.v1".`), + "lint", + filepath.Join("testdata", "workspace", "success", "v2", "symlink"), + ) } func TestWorkspaceAbsoluteFail(t *testing.T) { t.Parallel() - // The buf.work.yaml file cannot specify absolute paths. + // The workspace file (v1: buf.work.yaml, v2: buf.yaml) cannot specify absolute paths. testRunStdoutStderrNoWarn( t, nil, @@ -86,6 +126,15 @@ func TestWorkspaceAbsoluteFail(t *testing.T) { "build", filepath.Join("testdata", "workspace", "fail", "absolute"), ) + testRunStdoutStderrNoWarn( + t, + nil, + 1, + ``, + `Failure: decode testdata/workspace/fail/v2/absolute/buf.yaml: invalid module directory: /home/buf: expected to be relative`, + "build", + filepath.Join("testdata", "workspace", "fail", "v2", "absolute"), + ) } // TODO: Move this back to workspace_test.go. after resolving the issue where git @@ -141,4 +190,50 @@ func TestWorkspaceGit(t *testing.T) { "--path", filepath.Join("private", "buf", "cmd", "buf", "testdata", "workspace", "success", "dir", "proto", "rpc.proto"), ) + testRunStdout( + t, + nil, + 0, + ``, + "build", + "../../../../.git#ref=HEAD,subdir=private/buf/cmd/buf/testdata/workspace/success/v2/dir/proto", + ) + testRunStdout( + t, + nil, + 0, + ``, + "build", + "../../../../.git#ref=HEAD,subdir=private/buf/cmd/buf/testdata/workspace/success/v2/dir/proto", + "--path", + filepath.Join("private", "buf", "cmd", "buf", "testdata", "workspace", "success", "v2", "dir", "proto", "rpc.proto"), + ) + testRunStdout( + t, + nil, + 0, + filepath.FromSlash(`private/buf/cmd/buf/testdata/workspace/success/v2/dir/proto/rpc.proto`), + "ls-files", + "../../../../.git#ref=HEAD,subdir=private/buf/cmd/buf/testdata/workspace/success/v2/dir/proto", + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`private/buf/cmd/buf/testdata/workspace/success/v2/dir/proto/rpc.proto:3:1:Files with package "example" must be within a directory "example" relative to root but were in directory ".". + private/buf/cmd/buf/testdata/workspace/success/v2/dir/proto/rpc.proto:3:1:Package name "example" should be suffixed with a correctly formed version, such as "example.v1".`), + "lint", + "../../../../.git#ref=HEAD,subdir=private/buf/cmd/buf/testdata/workspace/success/v2/dir/proto", + ) + testRunStdout( + t, + nil, + bufctl.ExitCodeFileAnnotation, + filepath.FromSlash(`private/buf/cmd/buf/testdata/workspace/success/v2/dir/proto/rpc.proto:3:1:Files with package "example" must be within a directory "example" relative to root but were in directory ".". + private/buf/cmd/buf/testdata/workspace/success/v2/dir/proto/rpc.proto:3:1:Package name "example" should be suffixed with a correctly formed version, such as "example.v1".`), + "lint", + "../../../../.git#ref=HEAD,subdir=private/buf/cmd/buf/testdata/workspace/success/v2/dir/proto", + "--path", + filepath.Join("private", "buf", "cmd", "buf", "testdata", "workspace", "success", "v2", "dir", "proto", "rpc.proto"), + ) } diff --git a/private/buf/cmd/buf/workspace_windows_test.go b/private/buf/cmd/buf/workspace_windows_test.go index 06ac5a79d6..25d01c455b 100644 --- a/private/buf/cmd/buf/workspace_windows_test.go +++ b/private/buf/cmd/buf/workspace_windows_test.go @@ -23,7 +23,7 @@ import ( ) func TestWorkspaceAbsoluteFail(t *testing.T) { - // The buf.work.yaml file cannot specify absolute paths. + // The workspace file (v1: buf.work.yaml, v2: buf.yaml) file cannot specify absolute paths. testRunStdoutStderrNoWarn( t, nil, @@ -33,4 +33,13 @@ func TestWorkspaceAbsoluteFail(t *testing.T) { "build", filepath.Join("testdata", "workspace", "fail", "absolute", "windows"), ) + testRunStdoutStderrNoWarn( + t, + nil, + 1, + ``, + `Failure: directory "C:\buf" listed in testdata\workspace\fail\absolute\windows\buf.work.yaml is invalid: C:\buf: expected to be relative`, + "build", + filepath.Join("testdata", "workspace", "fail", "v2", "absolute", "windows"), + ) } diff --git a/private/bufpkg/bufcheck/buflint/buflint_test.go b/private/bufpkg/bufcheck/buflint/buflint_test.go index 39d866d7fc..d1584eb454 100644 --- a/private/bufpkg/bufcheck/buflint/buflint_test.go +++ b/private/bufpkg/bufcheck/buflint/buflint_test.go @@ -977,6 +977,65 @@ func TestRunIgnores4(t *testing.T) { ) } +func TestRunV2WorkspaceIgnores(t *testing.T) { + t.Parallel() + testLintWithOptions( + t, + "v2/ignores", + "ignores1", + nil, + bufanalysistesting.NewFileAnnotation(t, "bar1/bar.proto", 6, 9, 6, 15, "FIELD_LOWER_SNAKE_CASE"), + bufanalysistesting.NewFileAnnotation(t, "bar1/bar.proto", 9, 9, 9, 12, "MESSAGE_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "bar1/bar.proto", 13, 6, 13, 9, "ENUM_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "bar1/bar2.proto", 6, 9, 6, 15, "FIELD_LOWER_SNAKE_CASE"), + bufanalysistesting.NewFileAnnotation(t, "bar1/bar2.proto", 9, 9, 9, 13, "MESSAGE_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "bar1/bar2.proto", 13, 6, 13, 10, "ENUM_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "buf1.proto", 6, 9, 6, 15, "FIELD_LOWER_SNAKE_CASE"), + bufanalysistesting.NewFileAnnotation(t, "buf1.proto", 9, 9, 9, 12, "MESSAGE_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "buf1.proto", 13, 6, 13, 9, "ENUM_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "foo1/bar/bar.proto", 6, 9, 6, 15, "FIELD_LOWER_SNAKE_CASE"), + bufanalysistesting.NewFileAnnotation(t, "foo1/bar/bar.proto", 9, 9, 9, 12, "MESSAGE_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "foo1/bar/bar.proto", 13, 6, 13, 9, "ENUM_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "foo1/baz/baz.proto", 6, 9, 6, 15, "FIELD_LOWER_SNAKE_CASE"), + bufanalysistesting.NewFileAnnotation(t, "foo1/baz/baz.proto", 9, 9, 9, 12, "MESSAGE_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "foo1/baz/baz.proto", 13, 6, 13, 9, "ENUM_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "foo1/buf.proto", 6, 9, 6, 15, "FIELD_LOWER_SNAKE_CASE"), + bufanalysistesting.NewFileAnnotation(t, "foo1/buf.proto", 9, 9, 9, 12, "MESSAGE_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "foo1/buf.proto", 13, 6, 13, 9, "ENUM_PASCAL_CASE"), + ) + testLintWithOptions( + t, + "v2/ignores", + "ignores2", + nil, + bufanalysistesting.NewFileAnnotation(t, "bar2/bar.proto", 6, 9, 6, 15, "FIELD_LOWER_SNAKE_CASE"), + bufanalysistesting.NewFileAnnotation(t, "bar2/bar.proto", 9, 9, 9, 12, "MESSAGE_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "bar2/bar.proto", 13, 6, 13, 9, "ENUM_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "buf2.proto", 6, 9, 6, 15, "FIELD_LOWER_SNAKE_CASE"), + bufanalysistesting.NewFileAnnotation(t, "buf2.proto", 9, 9, 9, 12, "MESSAGE_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "buf2.proto", 13, 6, 13, 9, "ENUM_PASCAL_CASE"), + ) + testLintWithOptions( + t, + "v2/ignores", + "ignores3", + nil, + bufanalysistesting.NewFileAnnotation(t, "bar3/bar.proto", 6, 9, 6, 15, "FIELD_LOWER_SNAKE_CASE"), + bufanalysistesting.NewFileAnnotation(t, "bar3/bar2.proto", 6, 9, 6, 15, "FIELD_LOWER_SNAKE_CASE"), + bufanalysistesting.NewFileAnnotation(t, "bar3/bar2.proto", 9, 9, 9, 13, "MESSAGE_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "bar3/bar2.proto", 13, 6, 13, 10, "ENUM_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "buf3.proto", 6, 9, 6, 15, "FIELD_LOWER_SNAKE_CASE"), + bufanalysistesting.NewFileAnnotation(t, "buf3.proto", 9, 9, 9, 12, "MESSAGE_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "buf3.proto", 13, 6, 13, 9, "ENUM_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "foo3/baz/baz.proto", 6, 9, 6, 15, "FIELD_LOWER_SNAKE_CASE"), + bufanalysistesting.NewFileAnnotation(t, "foo3/baz/baz.proto", 9, 9, 9, 12, "MESSAGE_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "foo3/baz/baz.proto", 13, 6, 13, 9, "ENUM_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "foo3/buf.proto", 6, 9, 6, 15, "FIELD_LOWER_SNAKE_CASE"), + bufanalysistesting.NewFileAnnotation(t, "foo3/buf.proto", 9, 9, 9, 12, "MESSAGE_PASCAL_CASE"), + bufanalysistesting.NewFileAnnotation(t, "foo3/buf.proto", 13, 6, 13, 9, "ENUM_PASCAL_CASE"), + ) +} + func TestCommentIgnoresOff(t *testing.T) { t.Parallel() testLint( @@ -1119,21 +1178,30 @@ func testLintWithOptions( ) require.NoError(t, err) + // the module full name string represents the opaque ID of the module + opaqueID := moduleFullNameString + if opaqueID == "" { + opaqueID = "." + } + + // build the image for the specified module string (opaqueID) + moduleSet, err := workspace.WithTargetOpaqueIDs(opaqueID) + require.NoError(t, err) + module := moduleSet.GetModuleForOpaqueID(opaqueID) + require.NotNil(t, module) + moduleReadBucket, err := bufmodule.ModuleToSelfContainedModuleReadBucketWithOnlyProtoFiles(module) + require.NoError(t, err) image, err := bufimage.BuildImage( ctx, tracing.NopTracer, - bufmodule.ModuleSetToModuleReadBucketWithOnlyProtoFiles(workspace), + moduleReadBucket, ) require.NoError(t, err) if imageModifier != nil { image = imageModifier(image) } - if moduleFullNameString == "" { - // opaqueID - moduleFullNameString = "." - } - lintConfig := workspace.GetLintConfigForOpaqueID(moduleFullNameString) + lintConfig := workspace.GetLintConfigForOpaqueID(opaqueID) require.NotNil(t, lintConfig) handler := buflint.NewHandler(zap.NewNop(), tracing.NopTracer) err = handler.Check( diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/buf.yaml b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/buf.yaml new file mode 100644 index 0000000000..2c9c64bf87 --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/buf.yaml @@ -0,0 +1,31 @@ +version: v2 +modules: + - directory: ignores1 + lint: + use: + - ENUM_PASCAL_CASE + - FIELD_LOWER_SNAKE_CASE + - MESSAGE_PASCAL_CASE + - directory: ignores2 + lint: + use: + - ENUM_PASCAL_CASE + - FIELD_LOWER_SNAKE_CASE + - MESSAGE_PASCAL_CASE + ignore: + - ignores2/bar2/bar2.proto + - ignores2/foo2 + - directory: ignores3 + lint: + use: + - ENUM_PASCAL_CASE + - FIELD_LOWER_SNAKE_CASE + - MESSAGE_PASCAL_CASE + ignore_only: + BASIC: + - ignores3/foo3/bar + ENUM_PASCAL_CASE: + - ignores3/bar3/bar.proto + - ignores3/foo3/bar + MESSAGE_PASCAL_CASE: + - ignores3/bar3/bar.proto diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/bar1/bar.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/bar1/bar.proto new file mode 100644 index 0000000000..7a78284fb1 --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/bar1/bar.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf.bar1; + +message Foo { + int64 oneTwo = 1; +} + +message bar { + int64 three = 3; +} + +enum baz { + BAZ_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/bar1/bar2.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/bar1/bar2.proto new file mode 100644 index 0000000000..c96638d5c2 --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/bar1/bar2.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf.bar1; + +message Foo2 { + int64 oneTwo = 1; +} + +message bar2 { + int64 three = 3; +} + +enum baz2 { + BAZ2_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/buf1.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/buf1.proto new file mode 100644 index 0000000000..ebb88f60e2 --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/buf1.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf1; + +message Foo { + int64 oneTwo = 1; +} + +message biz { + int64 three = 3; +} + +enum buz { + BAZ_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/foo1/bar/bar.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/foo1/bar/bar.proto new file mode 100644 index 0000000000..4cd7fc073c --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/foo1/bar/bar.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf.foo.bar1; + +message Foo { + int64 oneTwo = 1; +} + +message bar { + int64 three = 3; +} + +enum baz { + BAZ_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/foo1/baz/baz.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/foo1/baz/baz.proto new file mode 100644 index 0000000000..7142516895 --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/foo1/baz/baz.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf.foo.baz; + +message Foo { + int64 oneTwo = 1; +} + +message bar { + int64 three = 3; +} + +enum baz { + BAZ_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/foo1/buf.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/foo1/buf.proto new file mode 100644 index 0000000000..dac94349ae --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores1/foo1/buf.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf.foo1; + +message Foo { + int64 oneTwo = 1; +} + +message biz { + int64 three = 3; +} + +enum buz { + BAZ_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/bar2/bar.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/bar2/bar.proto new file mode 100644 index 0000000000..90a9b319f2 --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/bar2/bar.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf.bar2; + +message Foo { + int64 oneTwo = 1; +} + +message bar { + int64 three = 3; +} + +enum baz { + BAZ_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/bar2/bar2.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/bar2/bar2.proto new file mode 100644 index 0000000000..408c63f1d7 --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/bar2/bar2.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf.bar2; + +message Foo2 { + int64 oneTwo = 1; +} + +message bar2 { + int64 three = 3; +} + +enum baz2 { + BAZ2_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/buf2.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/buf2.proto new file mode 100644 index 0000000000..e1b1d6897b --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/buf2.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf2; + +message Foo { + int64 oneTwo = 1; +} + +message biz { + int64 three = 3; +} + +enum buz { + BAZ_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/foo2/bar/bar.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/foo2/bar/bar.proto new file mode 100644 index 0000000000..c37bf5e116 --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/foo2/bar/bar.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf.foo.bar2; + +message Foo { + int64 oneTwo = 1; +} + +message bar { + int64 three = 3; +} + +enum baz { + BAZ_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/foo2/baz/baz.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/foo2/baz/baz.proto new file mode 100644 index 0000000000..75b7850e85 --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/foo2/baz/baz.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf.foo.baz2; + +message Foo { + int64 oneTwo = 1; +} + +message bar { + int64 three = 3; +} + +enum baz { + BAZ_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/foo2/buf.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/foo2/buf.proto new file mode 100644 index 0000000000..3298afc04c --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores2/foo2/buf.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf.foo2; + +message Foo { + int64 oneTwo = 1; +} + +message biz { + int64 three = 3; +} + +enum buz { + BAZ_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/bar3/bar.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/bar3/bar.proto new file mode 100644 index 0000000000..95285119e1 --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/bar3/bar.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf.bar3; + +message Foo { + int64 oneTwo = 1; +} + +message bar { + int64 three = 3; +} + +enum baz { + BAZ_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/bar3/bar2.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/bar3/bar2.proto new file mode 100644 index 0000000000..09b2cbf70e --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/bar3/bar2.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf.bar3; + +message Foo2 { + int64 oneTwo = 1; +} + +message bar2 { + int64 three = 3; +} + +enum baz2 { + BAZ2_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/buf3.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/buf3.proto new file mode 100644 index 0000000000..59bbd3425b --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/buf3.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf3; + +message Foo { + int64 oneTwo = 1; +} + +message biz { + int64 three = 3; +} + +enum buz { + BAZ_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/foo3/bar/bar.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/foo3/bar/bar.proto new file mode 100644 index 0000000000..136661d7ec --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/foo3/bar/bar.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf.foo.bar3; + +message Foo { + int64 oneTwo = 1; +} + +message bar { + int64 three = 3; +} + +enum baz { + BAZ_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/foo3/baz/baz.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/foo3/baz/baz.proto new file mode 100644 index 0000000000..d8bb2dc9db --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/foo3/baz/baz.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf.foo.baz3; + +message Foo { + int64 oneTwo = 1; +} + +message bar { + int64 three = 3; +} + +enum baz { + BAZ_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/foo3/buf.proto b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/foo3/buf.proto new file mode 100644 index 0000000000..69c494c2bd --- /dev/null +++ b/private/bufpkg/bufcheck/buflint/testdata/v2/ignores/ignores3/foo3/buf.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package buf.foo3; + +message Foo { + int64 oneTwo = 1; +} + +message biz { + int64 three = 3; +} + +enum buz { + BAZ_UNSPECIFIED = 0; +} diff --git a/private/bufpkg/bufconfig/buf_yaml_file.go b/private/bufpkg/bufconfig/buf_yaml_file.go index 07cb3470f7..8c3e86e32c 100644 --- a/private/bufpkg/bufconfig/buf_yaml_file.go +++ b/private/bufpkg/bufconfig/buf_yaml_file.go @@ -381,7 +381,7 @@ func readBufYAMLFile(reader io.Reader, fileName string, allowJSON bool) (BufYAML } dirPath, err := normalpath.NormalizeAndValidate(dirPath) if err != nil { - return nil, fmt.Errorf("invaid module directory: %w", err) + return nil, fmt.Errorf("invalid module directory: %w", err) } var moduleFullName bufmodule.ModuleFullName if externalModule.Name != "" { diff --git a/private/bufpkg/bufmodule/module_set_builder.go b/private/bufpkg/bufmodule/module_set_builder.go index a956fd3feb..6b3d902aae 100644 --- a/private/bufpkg/bufmodule/module_set_builder.go +++ b/private/bufpkg/bufmodule/module_set_builder.go @@ -93,6 +93,12 @@ type ModuleSetBuilder interface { // Build builds the Modules into a ModuleSet. // // Any errors from Add* calls will be returned here as well. + // + // For future consideration, `Build` can take ...buildOption. A use case for this + // would be for workspaces to have a unified/top-level README and/or LICENSE file. + // The workspace at build time can pass `BuildWithREADME` and/or `BuildWithLicense` for + // the module set. Then each module in the module set can refer to this through the module + // set as needed. Build() (ModuleSet, error) isModuleSetBuilder()