def test_deploy_multiple_schedule(self, monkeypatch): monkeypatch.setenv("GOOGLE_PROJECT", "goblet") monkeypatch.setenv("GOOGLE_LOCATION", "us-central1") monkeypatch.setenv("GOBLET_TEST_NAME", "schedule-deploy-multiple") monkeypatch.setenv("GOBLET_HTTP_TEST", "REPLAY") goblet_name = "goblet-test-schedule" scheduler = Scheduler(goblet_name) scheduler.register_job("test-job", None, kwargs={ "schedule": "* * 1 * *", "kwargs": {} }) scheduler.register_job( "test-job", None, kwargs={ "schedule": "* * 2 * *", "kwargs": { "httpMethod": "POST" } }, ) scheduler.register_job( "test-job", None, kwargs={ "schedule": "* * 3 * *", "kwargs": { "headers": { "X-HEADER": "header" } }, }, ) scheduler.deploy() post_job_1 = get_response( "schedule-deploy-multiple", "post-v1-projects-goblet-locations-us-central1-jobs_1.json", ) post_job_2 = get_response( "schedule-deploy-multiple", "post-v1-projects-goblet-locations-us-central1-jobs_2.json", ) post_job_3 = get_response( "schedule-deploy-multiple", "post-v1-projects-goblet-locations-us-central1-jobs_3.json", ) assert (post_job_1["body"]["httpTarget"]["headers"]["X-Goblet-Name"] == "test-job") assert (post_job_2["body"]["httpTarget"]["headers"]["X-Goblet-Name"] == "test-job-2") assert post_job_2["body"]["httpTarget"]["httpMethod"] == "POST" assert (post_job_3["body"]["httpTarget"]["headers"]["X-Goblet-Name"] == "test-job-3") assert post_job_3["body"]["httpTarget"]["headers"][ "X-HEADER"] == "header"
def test_deploy_pubsub_subscription_with_config(self, monkeypatch): monkeypatch.setenv("GOOGLE_PROJECT", "goblet") monkeypatch.setenv("GOOGLE_LOCATION", "us-central1") monkeypatch.setenv("GOBLET_TEST_NAME", "pubsub-deploy-subscription-config") monkeypatch.setenv("GOBLET_HTTP_TEST", "REPLAY") service_account = "*****@*****.**" app = Goblet(function_name="goblet-topic-subscription-config") setattr(app, "entrypoint", "app") app.topic("test", use_subscription=True, config={"enableExactlyOnceDelivery": True})(dummy_function) app.deploy( force=True, skip_function=True, config={"pubsub": { "serviceAccountEmail": service_account }}, ) put_subscription = get_response( "pubsub-deploy-subscription-config", "put-v1-projects-goblet-subscriptions-goblet-topic-subscription-config-test_1.json", ) responses = get_responses("pubsub-deploy-subscription-config") assert put_subscription["body"]["enableExactlyOnceDelivery"] assert len(responses) == 2
def test_deploy_pubsub_cross_project(self, monkeypatch, requests_mock): monkeypatch.setenv("GOOGLE_PROJECT", "goblet") monkeypatch.setenv("GOOGLE_LOCATION", "us-central1") monkeypatch.setenv("GOBLET_TEST_NAME", "pubsub-deploy-cross-project") monkeypatch.setenv("GOBLET_HTTP_TEST", "REPLAY") service_account = "*****@*****.**" requests_mock.register_uri("PUT", "https://storage.googleapis.com/mock") app = Goblet(function_name="goblet-topic-cross-project") setattr(app, "entrypoint", "app") app.topic("test", project="goblet-cross-project")(dummy_function) app.deploy(force=True, config={"pubsub": { "serviceAccountEmail": service_account }}) put_subscription = get_response( "pubsub-deploy-cross-project", "put-v1-projects-goblet-subscriptions-goblet-topic-cross-project-test_1.json", ) responses = get_responses("pubsub-deploy-cross-project") assert "goblet-cross-project" in put_subscription["body"]["topic"] assert len(responses) == 5
def test_cloudrun_custom_artifact(self, monkeypatch, requests_mock): monkeypatch.setenv("GOOGLE_PROJECT", "goblet") monkeypatch.setenv("GOOGLE_LOCATION", "us-central1") monkeypatch.setenv("GOBLET_TEST_NAME", "deployer-cloudrun-artifact") monkeypatch.setenv("GOBLET_HTTP_TEST", "REPLAY") requests_mock.register_uri("PUT", "https://storage.googleapis.com/mock") app = Goblet(function_name="goblet", backend="cloudrun") setattr(app, "entrypoint", "app") app.handlers["http"] = HTTP(dummy_function) app.deploy( only_function=True, force=True, config={ "cloudrun_revision": { "serviceAccount": "*****@*****.**" }, "cloudbuild": { "artifact_registry": "us-central1-docker.pkg.dev/newgoblet/cloud-run-source-deploy/goblet", "serviceAccount": "projects/goblet/serviceAccounts/[email protected]", }, }, ) response = get_response( "deployer-cloudrun-artifact", "post-v1-projects-goblet-builds_1.json" ) assert ( "newgoblet" in response["body"]["metadata"]["build"]["artifacts"]["images"][0] )
def test_deploy_routes(self, monkeypatch, requests_mock): monkeypatch.setenv("GOOGLE_PROJECT", "goblet") monkeypatch.setenv("GOOGLE_LOCATION", "us-central1") monkeypatch.setenv("GOBLET_TEST_NAME", "routes-deploy") monkeypatch.setenv("GOBLET_HTTP_TEST", "REPLAY") requests_mock.register_uri("PUT", "https://storage.googleapis.com/mock") app = Goblet(function_name="goblet_routes") setattr(app, "entrypoint", "app") app.route("/")(dummy_function) app.deploy(force=True) post_api = get_response( "routes-deploy", "post-v1-projects-goblet-locations-global-apis_1.json") post_config = get_response( "routes-deploy", "post-v1-projects-goblet-locations-global-apis-goblet-routes-configs_1.json", ) post_gw = get_response( "routes-deploy", "post-v1-projects-goblet-locations-us-central1-gateways_1.json", ) get_gw = get_response( "routes-deploy", "get-v1-projects-goblet-locations-us-central1-gateways-goblet-routes_1.json", ) assert post_api["body"]["metadata"]["verb"] == "create" assert post_api["body"]["metadata"]["target"].endswith("goblet-routes") assert post_config["body"]["metadata"]["verb"] == "create" assert post_config["body"]["metadata"]["target"].endswith( "goblet-routes") assert post_gw["body"]["metadata"]["verb"] == "create" assert post_gw["body"]["metadata"]["target"].endswith("goblet-routes") assert get_gw["body"]["state"] == "ACTIVE" assert get_gw["body"]["displayName"] == "goblet-routes"