@@ -6,9 +6,11 @@ import (
66 "time"
77
88 "github.com/docker/docker/client"
9+ "github.com/docker/go-connections/nat"
910 "github.com/pkg/errors"
1011 "github.com/smartcontractkit/chainlink-testing-framework/framework"
1112 "github.com/smartcontractkit/chainlink-testing-framework/framework/components/dockercompose/utils"
13+ "github.com/testcontainers/testcontainers-go"
1214 "github.com/testcontainers/testcontainers-go/modules/compose"
1315 "github.com/testcontainers/testcontainers-go/wait"
1416)
@@ -21,8 +23,12 @@ type Output struct {
2123}
2224
2325type BillingPlatformServiceOutput struct {
24- GRPCInternalURL string
25- GRPCExternalURL string
26+ BillingGRPCInternalURL string
27+ BillingGRPCExternalURL string
28+ CreditGRPCInternalURL string
29+ CreditGRPCExternalURL string
30+ OwnershipGRPCInternalURL string
31+ OwnershipGRPCExternalURL string
2632}
2733
2834type PostgresOutput struct {
@@ -46,8 +52,10 @@ func defaultBillingPlatformService(in *Input) *Input {
4652const (
4753 DEFAULT_STACK_NAME = "billing-platform-service"
4854
49- DEFAULT_BILLING_PLATFORM_SERVICE_GRPC_PORT = "2022"
50- DEFAULT_BILLING_PLATFORM_SERVICE_SERVICE_NAME = "billing-platform-service"
55+ DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT = "2222"
56+ DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT = "2223"
57+ DEFAULT_BILLING_PLATFORM_SERVICE_OWNERSHIP_GRPC_PORT = "2257"
58+ DEFAULT_BILLING_PLATFORM_SERVICE_SERVICE_NAME = "billing-platform-service"
5159)
5260
5361func New (in * Input ) (* Output , error ) {
@@ -90,7 +98,9 @@ func New(in *Input) (*Output, error) {
9098 stack .WaitForService (DEFAULT_BILLING_PLATFORM_SERVICE_SERVICE_NAME ,
9199 wait .ForAll (
92100 wait .ForLog ("GRPC server is live" ).WithPollInterval (200 * time .Millisecond ),
93- wait .ForListeningPort (DEFAULT_BILLING_PLATFORM_SERVICE_GRPC_PORT ),
101+ wait .ForListeningPort (DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT ),
102+ wait .ForListeningPort (DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT ),
103+ wait .ForListeningPort (DEFAULT_BILLING_PLATFORM_SERVICE_OWNERSHIP_GRPC_PORT ),
94104 ).WithDeadline (1 * time .Minute ),
95105 )
96106
@@ -141,17 +151,14 @@ func New(in *Input) (*Output, error) {
141151 return nil , errors .Wrap (billingExternalHostErr , "failed to get host for Billing Platform Service" )
142152 }
143153
144- // get mapped port for billing platform service
145- billingExternalPort , billingExternalPortErr := utils . FindMappedPort (ctx , 20 * time . Second , billingContainer , DEFAULT_BILLING_PLATFORM_SERVICE_GRPC_PORT )
146- if billingExternalPortErr != nil {
147- return nil , errors .Wrap (billingExternalPortErr , "failed to get mapped port for Chip Ingress " )
154+ // get mapped ports for billing platform service
155+ serviceOutput , err := getExternalPorts (ctx , billingExternalHost , billingContainer )
156+ if err != nil {
157+ return nil , errors .Wrap (err , "failed to get mapped port for Billing Platform Service " )
148158 }
149159
150160 output := & Output {
151- BillingPlatformService : & BillingPlatformServiceOutput {
152- GRPCInternalURL : fmt .Sprintf ("http://%s:%s" , DEFAULT_BILLING_PLATFORM_SERVICE_SERVICE_NAME , DEFAULT_BILLING_PLATFORM_SERVICE_GRPC_PORT ),
153- GRPCExternalURL : fmt .Sprintf ("http://%s:%s" , billingExternalHost , billingExternalPort .Port ()),
154- },
161+ BillingPlatformService : serviceOutput ,
155162 Postgres : & PostgresOutput {
156163 DSN : DefaultPostgresDSN ,
157164 },
@@ -161,3 +168,37 @@ func New(in *Input) (*Output, error) {
161168
162169 return output , nil
163170}
171+
172+ func getExternalPorts (ctx context.Context , billingExternalHost string , billingContainer * testcontainers.DockerContainer ) (* BillingPlatformServiceOutput , error ) {
173+ ports := map [string ]nat.Port {
174+ "billing" : DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT ,
175+ "credit" : DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT ,
176+ "ownership" : DEFAULT_BILLING_PLATFORM_SERVICE_OWNERSHIP_GRPC_PORT ,
177+ }
178+
179+ output := BillingPlatformServiceOutput {}
180+
181+ for name , defaultPort := range ports {
182+ externalPort , err := utils .FindMappedPort (ctx , 20 * time .Second , billingContainer , defaultPort )
183+ if err != nil {
184+ return nil , errors .Wrap (err , "failed to get mapped port for Billing Platform Service" )
185+ }
186+
187+ internal := fmt .Sprintf ("http://%s:%s" , DEFAULT_BILLING_PLATFORM_SERVICE_SERVICE_NAME , defaultPort )
188+ external := fmt .Sprintf ("http://%s:%s" , billingExternalHost , externalPort .Port ())
189+
190+ switch name {
191+ case "billing" :
192+ output .BillingGRPCInternalURL = internal
193+ output .BillingGRPCExternalURL = external
194+ case "credit" :
195+ output .CreditGRPCInternalURL = internal
196+ output .CreditGRPCExternalURL = external
197+ case "ownership" :
198+ output .OwnershipGRPCInternalURL = internal
199+ output .OwnershipGRPCExternalURL = external
200+ }
201+ }
202+
203+ return & output , nil
204+ }
0 commit comments