@@ -68,32 +68,63 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize
6868
6969// HttpEndpoint allows retrieving the Http endpoint where Microcks can be accessed
7070// (you'd have to append '/api' to access APIs)
71- func (container * MicrocksContainer ) HttpEndpoint (ctx context.Context ) string {
72- ip , _ := container .Host (ctx )
73- port , _ := container .MappedPort (ctx , DefaultHttpPort )
74- return fmt .Sprintf ("http://%s:%s" , ip , port .Port ())
71+ func (container * MicrocksContainer ) HttpEndpoint (ctx context.Context ) (string , error ) {
72+ ip , err := container .Host (ctx )
73+ if err != nil {
74+ return "" , err
75+ }
76+
77+ port , err := container .MappedPort (ctx , DefaultHttpPort )
78+ if err != nil {
79+ return "" , err
80+ }
81+
82+ return fmt .Sprintf ("http://%s:%s" , ip , port .Port ()), nil
7583}
7684
7785// SoapMockEndpoint get the exposed mock endpoint for a SOAP Service.
78- func (container * MicrocksContainer ) SoapMockEndpoint (ctx context.Context , service string , version string ) string {
79- return fmt .Sprintf ("%s/soap/%s/%s" , container .HttpEndpoint (ctx ), service , version )
86+ func (container * MicrocksContainer ) SoapMockEndpoint (ctx context.Context , service string , version string ) (string , error ) {
87+ endpoint , err := container .HttpEndpoint (ctx )
88+ if err != nil {
89+ return "" , err
90+ }
91+
92+ return fmt .Sprintf ("%s/soap/%s/%s" , endpoint , service , version ), nil
8093}
8194
8295// RestMockEndpoints get the exposed mock endpoint for a REST Service.
83- func (container * MicrocksContainer ) RestMockEndpoint (ctx context.Context , service string , version string ) string {
84- return fmt .Sprintf ("%s/rest/%s/%s" , container .HttpEndpoint (ctx ), service , version )
96+ func (container * MicrocksContainer ) RestMockEndpoint (ctx context.Context , service string , version string ) (string , error ) {
97+ endpoint , err := container .HttpEndpoint (ctx )
98+ if err != nil {
99+ return "" , err
100+ }
101+
102+ return fmt .Sprintf ("%s/rest/%s/%s" , endpoint , service , version ), nil
85103}
86104
87105// GraphQLMockEndpoint get the exposed mock endpoints for a GraphQL Service.
88- func (container * MicrocksContainer ) GrapQLMockEndpoint (ctx context.Context , service string , version string ) string {
89- return fmt .Sprintf ("%s/graphql/%s/%s" , container .HttpEndpoint (ctx ), service , version )
106+ func (container * MicrocksContainer ) GrapQLMockEndpoint (ctx context.Context , service string , version string ) (string , error ) {
107+ endpoint , err := container .HttpEndpoint (ctx )
108+ if err != nil {
109+ return "" , err
110+ }
111+
112+ return fmt .Sprintf ("%s/graphql/%s/%s" , endpoint , service , version ), nil
90113}
91114
92115// GrpcMockEndpoint get the exposed mock endpoint for a GRPC Service.
93- func (container * MicrocksContainer ) GrpcMockEndpoint (ctx context.Context ) string {
94- ip , _ := container .Host (ctx )
95- port , _ := container .MappedPort (ctx , DefaultGrpcPort )
96- return fmt .Sprintf ("grpc://%s:%s" , ip , port .Port ())
116+ func (container * MicrocksContainer ) GrpcMockEndpoint (ctx context.Context ) (string , error ) {
117+ ip , err := container .Host (ctx )
118+ if err != nil {
119+ return "" , err
120+ }
121+
122+ port , err := container .MappedPort (ctx , DefaultGrpcPort )
123+ if err != nil {
124+ return "" , err
125+ }
126+
127+ return fmt .Sprintf ("grpc://%s:%s" , ip , port .Port ()), nil
97128}
98129
99130// ImportAsMainArtifact imports an artifact as a primary or main one within the Microcks container.
@@ -109,7 +140,10 @@ func (container *MicrocksContainer) ImportAsSecondaryArtifact(ctx context.Contex
109140// TestEndpoint launches a conformance test on an endpoint.
110141func (container * MicrocksContainer ) TestEndpoint (ctx context.Context , testRequest * client.TestRequest ) (* client.TestResult , error ) {
111142 // Retrieve API endpoint.
112- httpEndpoint := container .HttpEndpoint (ctx )
143+ httpEndpoint , err := container .HttpEndpoint (ctx )
144+ if err != nil {
145+ return nil , fmt .Errorf ("error retrieving Microcks API endpoint: %w" , err )
146+ }
113147
114148 // Create Microcks client.
115149 c , err := client .NewClientWithResponses (httpEndpoint + "/api" )
@@ -154,7 +188,10 @@ func (container *MicrocksContainer) TestEndpoint(ctx context.Context, testReques
154188
155189func (container * MicrocksContainer ) importArtifact (ctx context.Context , artifactFilePath string , mainArtifact bool ) (int , error ) {
156190 // Retrieve API endpoint.
157- httpEndpoint := container .HttpEndpoint (ctx )
191+ httpEndpoint , err := container .HttpEndpoint (ctx )
192+ if err != nil {
193+ return http .StatusInternalServerError , fmt .Errorf ("error retrieving Microcks API endpoint: %w" , err )
194+ }
158195
159196 // Create Microcks client.
160197 c , err := client .NewClientWithResponses (httpEndpoint + "/api" )
0 commit comments