Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwrite with commit hash in buf.lock #29

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ func BufDir(dir string) Option {
if err := opt(r); err != nil {
return err
}
if _, err := os.Stat(filepath.Join(dir, bufLockFile)); err == nil {
opt := BufLock(filepath.Join(dir, bufLockFile))
if err := opt(r); err != nil {
return err
}
}
if r.version == "v2" {
return nil
}
Expand Down
17 changes: 17 additions & 0 deletions resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ func TestBufConfig(t *testing.T) {
t.Errorf("acme/world/v1/world.proto not found in %v", paths)
}
})

t.Run("v2 no modules", func(t *testing.T) {
r, err := New(BufConfig("testdata/bufroot_v2_no_modules/buf.yaml"))
if err != nil {
t.Fatal(err)
}
paths := r.Paths()
if !slices.Contains(paths, "buf/validate/validate.proto") {
t.Errorf("buf/validate/validate.proto not found in %v", paths)
}
if !slices.Contains(paths, "helloapis/acme/hello/v2/hello.proto") {
t.Errorf("helloapis/acme/hello/v2/hello.proto not found in %v", paths)
}
if !slices.Contains(paths, "worldapis/acme/world/v1/world.proto") {
t.Errorf("worldapis/acme/world/v1/world.proto not found in %v", paths)
}
})
}

func TestModule(t *testing.T) {
Expand Down
10 changes: 10 additions & 0 deletions testdata/bufroot_v2_no_modules/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: v2
managed:
enabled: true
override:
- file_option: go_package_prefix
value: example.com/testdata
plugins:
- local: protoc-gen-go
out: gen/go
opt: paths=source_relative
6 changes: 6 additions & 0 deletions testdata/bufroot_v2_no_modules/buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated by buf. DO NOT EDIT.
version: v2
deps:
- name: buf.build/bufbuild/protovalidate
commit: 46a4cf4ba1094a34bcd89a6c67163b4b
digest: b5:2076a950fdf4a8047064d55fd1d20ef21e6d745bf56e3edf557071abd4488ed48c9466d60831d8a03489dc1fcc8ceaa073d197411b59ecd873e28b1328034e0b
16 changes: 16 additions & 0 deletions testdata/bufroot_v2_no_modules/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: v2
deps:
- buf.build/bufbuild/protovalidate
lint:
use:
- DEFAULT
except:
- FIELD_NOT_REQUIRED
- PACKAGE_NO_IMPORT_CYCLE
disallow_comment_ignores: true
breaking:
use:
- FILE
except:
- EXTENSION_NO_DELETE
- FIELD_SAME_DEFAULT
18 changes: 18 additions & 0 deletions testdata/bufroot_v2_no_modules/helloapis/acme/hello/v2/hello.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";

package hello.v2;

import "buf/validate/validate.proto";

service HelloService {
rpc Hello(HelloRequest) returns (HelloResponse);
}

message HelloRequest {
string name = 1 [(buf.validate.field).string.min_len = 1];
}

message HelloResponse {
string message = 1;
}

18 changes: 18 additions & 0 deletions testdata/bufroot_v2_no_modules/worldapis/acme/world/v1/world.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";

package world.v2;

import "buf/validate/validate.proto";

service WorldService {
rpc World(WorldRequest) returns (WorldResponse);
}

message WorldRequest {
string name = 1 [(buf.validate.field).string.min_len = 1];
}

message WorldResponse {
string message = 1;
}