@@ -61,15 +61,21 @@ func defaultBillingPlatformService(in *Input) *Input {
6161}
6262
6363const (
64- DEFAULT_STACK_NAME = "billing-platform-service"
65-
6664 DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT = "2222"
6765 DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT = "2223"
6866 DEFAULT_POSTGRES_PORT = "5432"
6967 DEFAULT_BILLING_PLATFORM_SERVICE_SERVICE_NAME = "billing-platform-service"
7068 DEFAULT_POSTGRES_SERVICE_NAME = "postgres"
7169)
7270
71+ // New starts a Billing Platform Service stack using docker-compose. Various env vars are set to sensible defaults and
72+ // input values, but can be overridden by the host process env vars if needed.
73+ //
74+ // Import env vars that can be set to override defaults:
75+ // - TEST_OWNERS = comma separated list of workflow owners
76+ // - STREAMS_API_URL = URL for the Streams API; can use a mock server if needed
77+ // - STREAMS_API_KEY = API key if using a staging or prod Streams API
78+ // - STREAMS_API_SECRET = API secret if using a staging or prod Streams API
7379func New (in * Input ) (* Output , error ) {
7480 if in == nil {
7581 return nil , errors .New ("input is nil" )
@@ -80,12 +86,12 @@ func New(in *Input) (*Output, error) {
8086 }
8187
8288 in = defaultBillingPlatformService (in )
83- identifier := framework .DefaultTCName (DEFAULT_STACK_NAME )
89+ identifier := framework .DefaultTCName (DEFAULT_BILLING_PLATFORM_SERVICE_SERVICE_NAME )
8490 framework .L .Debug ().Str ("Compose file" , in .ComposeFile ).
8591 Msgf ("Starting Billing Platform Service stack with identifier %s" ,
86- framework .DefaultTCName (DEFAULT_STACK_NAME ))
92+ framework .DefaultTCName (DEFAULT_BILLING_PLATFORM_SERVICE_SERVICE_NAME ))
8793
88- cFilePath , fileErr := utils .ComposeFilePath (in .ComposeFile , DEFAULT_STACK_NAME )
94+ cFilePath , fileErr := utils .ComposeFilePath (in .ComposeFile , DEFAULT_BILLING_PLATFORM_SERVICE_SERVICE_NAME )
8995 if fileErr != nil {
9096 return nil , errors .Wrap (fileErr , "failed to get compose file path" )
9197 }
@@ -105,6 +111,8 @@ func New(in *Input) (*Output, error) {
105111 // set development defaults for necessary environment variables and allow them to be overridden by the host process
106112 envVars := make (map [string ]string )
107113
114+ envVars ["BILLING_SERVICE_PORT" ] = DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT
115+ envVars ["CREDIT_RESERVATION_SERVICE_PORT" ] = DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT
108116 envVars ["MAINNET_WORKFLOW_REGISTRY_CHAIN_SELECTOR" ] = strconv .FormatUint (in .ChainSelector , 10 )
109117 envVars ["MAINNET_WORKFLOW_REGISTRY_CONTRACT_ADDRESS" ] = in .WorkflowRegistryAddress
110118 envVars ["MAINNET_WORKFLOW_REGISTRY_RPC_URL" ] = in .RPCURL
@@ -151,8 +159,8 @@ func New(in *Input) (*Output, error) {
151159 stack .WaitForService (DEFAULT_BILLING_PLATFORM_SERVICE_SERVICE_NAME ,
152160 wait .ForAll (
153161 wait .ForLog ("GRPC server is live" ).WithPollInterval (200 * time .Millisecond ),
154- wait .ForListeningPort (DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT ),
155- wait .ForListeningPort (DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT ),
162+ wait .ForListeningPort (nat . Port ( envVars [ "BILLING_SERVICE_PORT" ]) ),
163+ wait .ForListeningPort (nat . Port ( envVars [ "CREDIT_RESERVATION_SERVICE_PORT" ]) ),
156164 ).WithDeadline (1 * time .Minute ),
157165 )
158166
@@ -215,7 +223,7 @@ func New(in *Input) (*Output, error) {
215223 }
216224
217225 // get mapped ports for billing platform service
218- serviceOutput , err := getExternalPorts (ctx , billingExternalHost , billingContainer )
226+ serviceOutput , err := getExternalPorts (ctx , billingExternalHost , envVars , billingContainer )
219227 if err != nil {
220228 return nil , errors .Wrap (err , "failed to get mapped port for Billing Platform Service" )
221229 }
@@ -237,10 +245,10 @@ func New(in *Input) (*Output, error) {
237245 return output , nil
238246}
239247
240- func getExternalPorts (ctx context.Context , billingExternalHost string , billingContainer * testcontainers.DockerContainer ) (* BillingPlatformServiceOutput , error ) {
248+ func getExternalPorts (ctx context.Context , billingExternalHost string , envVars map [ string ] string , billingContainer * testcontainers.DockerContainer ) (* BillingPlatformServiceOutput , error ) {
241249 ports := map [string ]nat.Port {
242- "billing" : DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT ,
243- "credit" : DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT ,
250+ "billing" : nat . Port ( envVars [ "BILLING_SERVICE_PORT" ]) ,
251+ "credit" : nat . Port ( envVars [ "CREDIT_RESERVATION_SERVICE_PORT" ]) ,
244252 }
245253
246254 output := BillingPlatformServiceOutput {}
0 commit comments