Skip to content

Commit

Permalink
tests(helpers): target grpc service makefile
Browse files Browse the repository at this point in the history
Add a makefile to grpc target service and simplify test helper.
  • Loading branch information
gszr committed Jan 22, 2025
1 parent cd9ac02 commit 2011bf2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 36 deletions.
20 changes: 20 additions & 0 deletions spec/fixtures/grpc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ALL= targetservice/targetservice.pb.go targetservice/targetservice_grpc.pb.go target

all: $(ALL)

.PHONY: go

clean:
rm -rf $(ALL)

go:
go mod tidy && go mod download all

target: go targetservice/targetservice.pb.go targetservice/targetservice_grpc.pb.go target.go
go build -o $@

targetservice/targetservice.pb.go: proto/targetservice.proto
protoc -I proto/ --go_out=. --go-grpc_out=. proto/targetservice.proto

targetservice/targetservice_grpc.pb.go: proto/targetservice.proto
protoc -I proto/ --go_out=. --go-grpc_out=. proto/targetservice.proto
39 changes: 3 additions & 36 deletions spec/internal/grpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,12 @@ local resty_signal = require("resty.signal")
local CONSTANTS = require("spec.internal.constants")


local function isnewer(path_a, path_b)
if not pl_path.exists(path_a) then
return true
end
if not pl_path.exists(path_b) then
return false
end
return assert(pl_path.getmtime(path_b)) > assert(pl_path.getmtime(path_a))
end


local function make(workdir, specs)
workdir = pl_path.normpath(workdir or pl_path.currentdir())

for _, spec in ipairs(specs) do
local targetpath = pl_path.join(workdir, spec.target)
for _, src in ipairs(spec.src) do
local srcpath = pl_path.join(workdir, src)
if isnewer(targetpath, srcpath) then
local ok, _, stderr = shell.run(string.format("cd %s; %s", workdir, spec.cmd), nil, 0)
assert(ok, stderr)
if isnewer(targetpath, srcpath) then
error(string.format("couldn't make %q newer than %q", targetpath, srcpath))
end
break
end
end
local ok, _, stderr = shell.run(string.format("cd %s; %s", workdir, spec.cmd), nil, 0)
assert(ok, stderr)
end

return true
Expand All @@ -46,19 +25,7 @@ local function start_grpc_target()
local ngx_pipe = require("ngx.pipe")
assert(make(CONSTANTS.GRPC_TARGET_SRC_PATH, {
{
target = "targetservice/targetservice.pb.go",
src = { "../targetservice.proto" },
cmd = "protoc --go_out=. --go-grpc_out=. -I ../ ../targetservice.proto",
},
{
target = "targetservice/targetservice_grpc.pb.go",
src = { "../targetservice.proto" },
cmd = "protoc --go_out=. --go-grpc_out=. -I ../ ../targetservice.proto",
},
{
target = "target",
src = { "grpc-target.go", "targetservice/targetservice.pb.go", "targetservice/targetservice_grpc.pb.go" },
cmd = "go mod tidy && go mod download all && go build",
cmd = "make clean && make all",
},
}))
grpc_target_proc = assert(ngx_pipe.spawn({ CONSTANTS.GRPC_TARGET_SRC_PATH .. "/target" }, {
Expand Down

0 comments on commit 2011bf2

Please sign in to comment.