From 26ae7a8a6710533d4c2c50e93ca8c2bcf75a267d Mon Sep 17 00:00:00 2001 From: maleo Date: Thu, 21 Sep 2023 21:59:24 +0000 Subject: [PATCH] Add test with explicit and implicit importpath --- .../go_proto_library_importpath/BUILD.bazel | 36 +++++++++++++++++++ .../go_proto_library_importpath/bar.proto | 9 +++++ .../go_proto_library_importpath/foo.proto | 7 ++++ .../importpath_test.go | 22 ++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 tests/core/go_proto_library_importpath/BUILD.bazel create mode 100644 tests/core/go_proto_library_importpath/bar.proto create mode 100644 tests/core/go_proto_library_importpath/foo.proto create mode 100644 tests/core/go_proto_library_importpath/importpath_test.go diff --git a/tests/core/go_proto_library_importpath/BUILD.bazel b/tests/core/go_proto_library_importpath/BUILD.bazel new file mode 100644 index 0000000000..90fdbfc7f6 --- /dev/null +++ b/tests/core/go_proto_library_importpath/BUILD.bazel @@ -0,0 +1,36 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") +load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +# Common rules +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], +) + +go_proto_library( + name = "foo_go_proto", + importpath = "path/to/foo_go", + proto = ":foo_proto", +) + +proto_library( + name = "bar_proto", + srcs = ["bar.proto"], + deps = [":foo_proto"], +) + +go_proto_library( + name = "bar_go_proto", + proto = ":bar_proto", + deps = [":foo_go_proto"], +) + +go_test( + name = "importpath_test", + srcs = ["importpath_test.go"], + deps = [ + ":bar_go_proto", + ":foo_go_proto", + ], +) diff --git a/tests/core/go_proto_library_importpath/bar.proto b/tests/core/go_proto_library_importpath/bar.proto new file mode 100644 index 0000000000..373f237219 --- /dev/null +++ b/tests/core/go_proto_library_importpath/bar.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package tests.core.go_proto_library_importpath.bar; + +import "tests/core/go_proto_library_importpath/foo.proto"; + +message Bar { + foo.Foo value = 1; +} diff --git a/tests/core/go_proto_library_importpath/foo.proto b/tests/core/go_proto_library_importpath/foo.proto new file mode 100644 index 0000000000..bc354cacc4 --- /dev/null +++ b/tests/core/go_proto_library_importpath/foo.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package tests.core.go_proto_library_importpath.foo; + +message Foo { + int64 value = 1; +} diff --git a/tests/core/go_proto_library_importpath/importpath_test.go b/tests/core/go_proto_library_importpath/importpath_test.go new file mode 100644 index 0000000000..3de6569c22 --- /dev/null +++ b/tests/core/go_proto_library_importpath/importpath_test.go @@ -0,0 +1,22 @@ +package importpath_test + +import ( + "fmt" + "testing" + + bar_proto "tests/core/go_proto_library_importpath/bar_go_proto" + foo_proto "path/to/foo_go" +) + +func Test(t *testing.T) { + bar := &bar_proto.Bar{} + bar.Value = &foo_proto.Foo{} + bar.Value.Value = 5 + + var expected int64 = 5 + if bar.Value.Value != expected { + t.Errorf(fmt.Sprintf("Not equal: \n"+ + "expected: %s\n"+ + "actual : %s", expected, bar.Value.Value)) + } +}