Skip to content

Commit

Permalink
build: introduce 'env.json' file to npm test rule
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Feb 15, 2024
1 parent c987f79 commit 76adbe8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 99 deletions.
81 changes: 2 additions & 79 deletions core/api/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -182,25 +182,7 @@ jest_test(
name = "unit-tests",
srcs = [":src"] + [":test_src"] + glob(["galoy.yaml"]),
config_file = "test/unit/jest.config.js",
app_env = {
"HELMREVISION": "dummy",
"KRATOS_PG_CON": "pg://dummy",
"OATHKEEPER_DECISION_ENDPOINT": "http://dummy",
"NETWORK": "regtest",
"TWILIO_ACCOUNT_SID": "dummy",
"TWILIO_AUTH_TOKEN": "dummy",
"TWILIO_VERIFY_SERVICE_ID": "dummy",
"KRATOS_PUBLIC_API": "http://dummy",
"KRATOS_ADMIN_API": "http://dummy",
"KRATOS_MASTER_USER_PASSWORD": "dummy",
"BRIA_HOST": "dummy",
"BRIA_API_KEY": "dummy",
"NOTIFICATIONS_HOST": "dummy",
"MONGODB_CON": "mongodb://dummy",
"REDIS_MASTER_NAME": "dummy",
"REDIS_PASSWORD": "dummy",
"REDIS_0_DNS": "dummy",
},
env_json_target = "//dev:env.json",
env = {
"LOGLEVEL": "warn",
}
Expand All @@ -212,66 +194,7 @@ jest_test(
prod_deps_srcs = prod_deps_srcs,
config_file = "test/integration/jest.config.js",
run_serially = True,
app_env = {
"HELMREVISION": "dev",
"NETWORK": "regtest",
"OATHKEEPER_DECISION_ENDPOINT": "http://localhost:4456",
"TWILIO_ACCOUNT_SID": "AC_twilio_id",
"TWILIO_AUTH_TOKEN": "AC_twilio_auth_token",
"TWILIO_VERIFY_SERVICE_ID": "VA_twilio_service",
"KRATOS_PG_CON": "postgres://dbuser:secret@localhost:5432/default?sslmode=disable",
"KRATOS_PUBLIC_API": "http://localhost:4433",
"KRATOS_ADMIN_API": "http://localhost:4434",
"KRATOS_MASTER_USER_PASSWORD": "passwordHardtoFindWithNumber123",
"PRICE_HOST": "localhost",
"PRICE_HISTORY_HOST": "localhost",
"BRIA_HOST": "localhost",
"BRIA_API_KEY": "bria_dev_000000000000000000000",
"NOTIFICATIONS_HOST": "localhost",
"MONGODB_CON": "mongodb://localhost:27017/galoy",
"REDIS_MASTER_NAME": "mymaster",
"REDIS_PASSWORD": "",
"REDIS_0_DNS": "localhost",
"REDIS_0_PORT": "6379",
"REDIS_TYPE": "standalone",
"UNSECURE_IP_FROM_REQUEST_OBJECT": "true",
"UNSECURE_DEFAULT_LOGIN_CODE": "000000",
"GEETEST_ID": "geetest_id",
"GEETEST_KEY": "geetest_key",

"SVIX_SECRET": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2OTE2NzIwMTQsImV4cCI6MjAwNzAzMjAxNCwibmJmIjoxNjkxNjcyMDE0LCJpc3MiOiJzdml4LXNlcnZlciIsInN1YiI6Im9yZ18yM3JiOFlkR3FNVDBxSXpwZ0d3ZFhmSGlyTXUifQ.b9s0aWSisNdUNki4edabBEToLNSwjC9-AiJQr4J3y4E",
"SVIX_ENDPOINT": "http://localhost:8071",
"EXPORTER_PORT": "3003",

"LND1_TLS": "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNZVENDQWdlZ0F3SUJBZ0lSQU9zZzdYWFR4cnVZYlhkeTY2d3RuN1F3Q2dZSUtvWkl6ajBFQXdJd09ERWYKTUIwR0ExVUVDaE1XYkc1a0lHRjFkRzluWlc1bGNtRjBaV1FnWTJWeWRERVZNQk1HQTFVRUF4TU1PRFl4T1RneApNak5tT0Roak1CNFhEVEl6TURFeE9USXdOREUxTTFvWERUTTBNRGN5TVRJd05ERTFNMW93T0RFZk1CMEdBMVVFCkNoTVdiRzVrSUdGMWRHOW5aVzVsY21GMFpXUWdZMlZ5ZERFVk1CTUdBMVVFQXhNTU9EWXhPVGd4TWpObU9EaGoKTUZrd0V3WUhLb1pJemowQ0FRWU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dyaXRlGhgKBnNpZ25lchIIZ2VuZXJhdGUSBHJlYWQAAAYg2XkV+4Z4inbfXGZivRoY+r7KHNZhgxkCEdKByxbeb/Q=",
"LNDOUTSIDE2ADDR": "localhost",
"LNDOUTSIDE2RPCPORT": "10013",
},
env_json_target = "//dev:env.json",
env = {
"LOGLEVEL": "warn",
}
Expand Down
17 changes: 7 additions & 10 deletions toolchains/workspace-pnpm/macros.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,9 @@ def _npm_test_impl(
cmd_args(program_run_info),
])

if hasattr(ctx.attrs, 'app_env'):
for key, val in ctx.attrs.app_env.items():
run_cmd_args.add("--app-env")
run_cmd_args.add('{}={}'.format(key, str(val).strip('"')))
if hasattr(ctx.attrs, 'env_json_target'):
run_cmd_args.add("--env-json-target")
run_cmd_args.add(ctx.attrs.env_json_target)

run_cmd_args.add("--")
run_cmd_args.add(program_args)
Expand Down Expand Up @@ -1166,12 +1165,10 @@ _jest_test = rule(
default = False,
doc = "Run all tests serially in the current process"
),
"app_env": attrs.dict(
key = attrs.string(),
value = attrs.arg(),
sorted = False,
default = {},
doc = """Set environment variables required by the application.""",
"env_json_target": attrs.option(
attrs.string(),
doc = """buck2 target for json file with env variables required.""",
default = None,
),
"env": attrs.dict(
key = attrs.string(),
Expand Down
42 changes: 32 additions & 10 deletions toolchains/workspace-pnpm/run_npm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,38 @@
Runs a program in a directory.
"""
import argparse
import json
import os
import subprocess
import sys

def env_dict_from_target(target):
repo_root_cmd = ["git", "rev-parse", "--show-toplevel"]
repo_root_res = subprocess.run(repo_root_cmd, capture_output=True, text=True)
if repo_root_res.returncode != 0:
raise RuntimeError(repo_root_res.stderr)
repo_root = repo_root_res.stdout.strip()

env_json_cmd = [
"buck2",
"--isolation-dir",
"buck-out",
"uquery",
"inputs(deps('{}'))".format(target),
]
env_json_res = subprocess.run(env_json_cmd, capture_output=True, text=True)
if env_json_res.returncode != 0:
raise RuntimeError(env_json_res.stderr)
env_json = env_json_res.stdout.strip()


abs_file_path = "{}/{}".format(repo_root, env_json)
with open(abs_file_path, 'r') as file:
env_dict = json.load(file)

return env_dict


if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
Expand All @@ -18,15 +46,9 @@
help="Binary to execute program with",
)
parser.add_argument(
"--env-file",
"--env-json-target",
help="Env file to load variables from",
)
parser.add_argument(
"--app-env",
action="append",
default=[],
help="Add an app env variable"
)
parser.add_argument(
"args",
help="Program and arguments",
Expand All @@ -36,9 +58,9 @@
args = parser.parse_args()

env = os.environ.copy()
for env_pair in args.app_env:
key, val = env_pair.split('=', 1)
env[key] = val
if (args.env_json_target):
env_json = env_dict_from_target(args.env_json_target)
env = {**env, **env_json}

bin_args = args.args[1:] # ignore '--' separator
if env.get("TEST"):
Expand Down

0 comments on commit 76adbe8

Please sign in to comment.