@@ -59,13 +59,25 @@ mqtt_port ?= 1883
5959mqtt_user ?= maestro
6060mqtt_password_file ?= ${PWD}/secrets/mqtt.password
6161mqtt_config_file ?= ${PWD}/secrets/mqtt.config
62+ mqtt_image ?= quay.io/maestro/eclipse-mosquitto:2.0.18
63+
64+ # Pub/Sub emulator configuration
65+ pubsub_host ?= maestro-pubsub.$(namespace )
66+ pubsub_port ?= 8085
67+ pubsub_project_id ?= maestro-test
68+ pubsub_config_file ?= ${PWD}/secrets/pubsub.config
69+ pubsub_image ?= gcr.io/google.com/cloudsdktool/google-cloud-cli:emulators
6270
6371# Log verbosity level
6472klog_v: =2
6573
74+ # message driver type, mqtt, grpc or pubsub, default is mqtt.
75+ MESSAGE_DRIVER_TYPE ?= mqtt
76+
6677# Test output files
6778unit_test_json_output ?= ${PWD}/unit-test-results.json
6879mqtt_integration_test_json_output ?= ${PWD}/mqtt-integration-test-results.json
80+ pubsub_integration_test_json_output ?= ${PWD}/pubsub-integration-test-results.json
6981grpc_integration_test_json_output ?= ${PWD}/grpc-integration-test-results.json
7082
7183# Prints a list of useful targets.
7789 @echo " make lint run golangci-lint"
7890 @echo " make binary compile binaries"
7991 @echo " make install compile binaries and install in GOPATH bin"
92+ @echo " make db/setup setup local PostgreSQL database"
93+ @echo " make db/teardown teardown local PostgreSQL database"
94+ @echo " make mqtt/setup setup local MQTT broker"
95+ @echo " make mqtt/teardown teardown local MQTT broker"
96+ @echo " make pubsub/setup setup local Pub/Sub emulator"
97+ @echo " make pubsub/init initialize Pub/Sub topics and subscriptions"
98+ @echo " make pubsub/teardown teardown local Pub/Sub emulator"
8099 @echo " make run run the application"
81100 @echo " make run/docs run swagger and host the api spec"
82101 @echo " make test run unit tests"
@@ -206,16 +225,21 @@ test:
206225# make test-integration TESTFLAGS="-run TestAccounts" acts as TestAccounts* and run TestAccountsGet, TestAccountsPost, etc.
207226# make test-integration TESTFLAGS="-run TestAccountsGet" runs TestAccountsGet
208227# make test-integration TESTFLAGS="-short" skips long-run tests
209- test-integration : test-integration-mqtt test-integration-grpc
228+ test-integration : test-integration-mqtt test-integration-pubsub test-integration- grpc
210229.PHONY : test-integration
211230
212231test-integration-mqtt :
213- BROKER =mqtt MAESTRO_ENV=testing gotestsum --jsonfile-timing-events=$(mqtt_integration_test_json_output ) --format $(TEST_SUMMARY_FORMAT ) -- -p 1 -ldflags -s -v -timeout 1h $(TESTFLAGS ) \
232+ MESSAGE_DRIVER_TYPE =mqtt MESSAGE_DRIVER_CONFIG= $( PWD ) /secrets/mqtt.config MAESTRO_ENV=testing gotestsum --jsonfile-timing-events=$(mqtt_integration_test_json_output ) --format $(TEST_SUMMARY_FORMAT ) -- -count=1 -p 1 -ldflags -s -v -timeout 1h $(TESTFLAGS ) \
214233 ./test/integration
215234.PHONY : test-integration-mqtt
216235
236+ test-integration-pubsub :
237+ MESSAGE_DRIVER_TYPE=pubsub MESSAGE_DRIVER_CONFIG=$(PWD ) /secrets/pubsub.config PUBSUB_EMULATOR_HOST=localhost:$(pubsub_port ) MAESTRO_ENV=testing gotestsum --jsonfile-timing-events=$(pubsub_integration_test_json_output ) --format $(TEST_SUMMARY_FORMAT ) -- -count=1 -p 1 -ldflags -s -v -timeout 1h $(TESTFLAGS ) \
238+ ./test/integration
239+ .PHONY : test-integration-pubsub
240+
217241test-integration-grpc :
218- BROKER =grpc MAESTRO_ENV=testing gotestsum --jsonfile-timing-events=$(grpc_integration_test_json_output ) --format $(TEST_SUMMARY_FORMAT ) -- -count=1 -p 1 -ldflags -s -v -timeout 1h $(TESTFLAGS ) \
242+ MESSAGE_DRIVER_TYPE =grpc MAESTRO_ENV=testing gotestsum --jsonfile-timing-events=$(grpc_integration_test_json_output ) --format $(TEST_SUMMARY_FORMAT ) -- -count=1 -p 1 -ldflags -s -v -timeout 1h $(TESTFLAGS ) \
219243 ./test/integration
220244.PHONY : test-integration-grpc
221245
@@ -230,7 +254,11 @@ generate:
230254
231255run : install
232256 maestro migration
233- maestro server
257+ @if [ " $( MESSAGE_DRIVER_TYPE) " = " grpc" ]; then \
258+ maestro server --message-broker-type=$(MESSAGE_DRIVER_TYPE ) ; \
259+ else \
260+ maestro server --message-broker-type=$(MESSAGE_DRIVER_TYPE ) --message-broker-config-file=./secrets/$(MESSAGE_DRIVER_TYPE ) .config; \
261+ fi
234262.PHONY : run
235263
236264# Run Swagger and host the api docs
@@ -325,14 +353,29 @@ mqtt/prepare:
325353.PHONY : mqtt/setup
326354mqtt/setup : mqtt/prepare
327355 @echo ' {"brokerHost":"localhost:1883","username":"$(mqtt_user)","password":"$(shell cat $(mqtt_password_file))","topics":{"sourceEvents":"sources/maestro/consumers/+/sourceevents","agentEvents":"sources/maestro/consumers/+/agentevents"}}' > $(mqtt_config_file )
328- $(container_tool ) run --rm -v $(shell pwd) /hack:/mosquitto/data:z $(MQTT_IMAGE ) mosquitto_passwd -c -b /mosquitto/data/mosquitto-passwd.txt $(mqtt_user ) $(shell cat $(mqtt_password_file ) )
329- $(container_tool ) run --name mqtt-maestro -p 1883:1883 -v $(shell pwd) /hack/mosquitto-passwd.txt:/mosquitto/config/password.txt -v $(shell pwd) /hack/mosquitto.conf:/mosquitto/config/mosquitto.conf -d $(MQTT_IMAGE )
356+ $(container_tool ) run --rm -v $(shell pwd) /hack:/mosquitto/data:z $(mqtt_image ) mosquitto_passwd -c -b /mosquitto/data/mosquitto-passwd.txt $(mqtt_user ) $(shell cat $(mqtt_password_file ) )
357+ $(container_tool ) run --name mqtt-maestro -p 1883:1883 -v $(shell pwd) /hack/mosquitto-passwd.txt:/mosquitto/config/password.txt -v $(shell pwd) /hack/mosquitto.conf:/mosquitto/config/mosquitto.conf -d $(mqtt_image )
330358
331359.PHONY : mqtt/teardown
332360mqtt/teardown :
333361 $(container_tool ) stop mqtt-maestro
334362 $(container_tool ) rm mqtt-maestro
335363
364+ .PHONY : pubsub/setup
365+ pubsub/setup :
366+ @mkdir -p ${PWD} /secrets
367+ @echo ' {"projectID":"$(pubsub_project_id)","endpoint":"localhost:$(pubsub_port)","insecure":true,"topics":{"sourceEvents":"projects/$(pubsub_project_id)/topics/sourceevents","sourceBroadcast":"projects/$(pubsub_project_id)/topics/sourcebroadcast"},"subscriptions":{"agentEvents":"projects/$(pubsub_project_id)/subscriptions/agentevents-maestro","agentBroadcast":"projects/$(pubsub_project_id)/subscriptions/agentbroadcast-maestro"}}' > $(pubsub_config_file )
368+ $(container_tool ) run --name pubsub-maestro -p $(pubsub_port ) :8085 -e PUBSUB_PROJECT_ID=$(pubsub_project_id ) -d $(pubsub_image ) gcloud beta emulators pubsub start --host-port=0.0.0.0:8085 --project=$(pubsub_project_id )
369+
370+ .PHONY : pubsub/teardown
371+ pubsub/teardown :
372+ $(container_tool ) stop pubsub-maestro
373+ $(container_tool ) rm pubsub-maestro
374+
375+ .PHONY : pubsub/init
376+ pubsub/init :
377+ @PUBSUB_EMULATOR_HOST=localhost:$(pubsub_port ) PUBSUB_PROJECT_ID=$(pubsub_project_id ) bash hack/init-pubsub-emulator.sh
378+
336379crc/login :
337380 @echo " Logging into CRC"
338381 @crc console --credentials -ojson | jq -r .clusterConfig.adminCredentials.password | oc login --username kubeadmin --insecure-skip-tls-verify=true https://api.crc.testing:6443
0 commit comments