@@ -15,6 +15,11 @@ const (
1515
1616 // bigQueryDataYamlPath is the path to the data yaml file in the container.
1717 bigQueryDataYamlPath = "/testcontainers-data.yaml"
18+
19+ defaultPortNumber9050 = "9050"
20+ defaultPortNumber9060 = "9060"
21+ defaultPort9050 = defaultPortNumber9050 + "/tcp"
22+ defaultPort9060 = defaultPortNumber9060 + "/tcp"
1823)
1924
2025// Container represents the BigQuery container type used in the module
@@ -36,44 +41,39 @@ func (c *Container) URI() string {
3641// Run creates an instance of the BigQuery GCloud container type.
3742// The URI uses http:// as the protocol.
3843func Run (ctx context.Context , img string , opts ... testcontainers.ContainerCustomizer ) (* Container , error ) {
39- req := testcontainers.GenericContainerRequest {
40- ContainerRequest : testcontainers.ContainerRequest {
41- Image : img ,
42- ExposedPorts : []string {"9050/tcp" , "9060/tcp" },
43- WaitingFor : wait .ForAll (
44- wait .ForListeningPort ("9050/tcp" ),
45- wait .ForHTTP ("/discovery/v1/apis/bigquery/v2/rest" ).WithPort ("9050/tcp" ).WithStatusCodeMatcher (func (status int ) bool {
46- return status == 200
47- }).WithStartupTimeout (time .Second * 5 ),
48- ),
49- },
50- Started : true ,
44+ moduleOpts := []testcontainers.ContainerCustomizer {
45+ testcontainers .WithExposedPorts (defaultPort9050 , defaultPort9060 ),
46+ testcontainers .WithWaitStrategy (wait .ForAll (
47+ wait .ForListeningPort (defaultPort9050 ),
48+ wait .ForHTTP ("/discovery/v1/apis/bigquery/v2/rest" ).WithPort (defaultPort9050 ).WithStatusCodeMatcher (func (status int ) bool {
49+ return status == 200
50+ }).WithStartupTimeout (time .Second * 5 ),
51+ )),
5152 }
5253
5354 settings := defaultOptions ()
5455 for _ , opt := range opts {
5556 if apply , ok := opt .(Option ); ok {
5657 if err := apply (& settings ); err != nil {
57- return nil , err
58+ return nil , fmt . Errorf ( "apply option: %w" , err )
5859 }
5960 }
60- if err := opt .Customize (& req ); err != nil {
61- return nil , err
62- }
6361 }
6462
65- req .Cmd = append (req .Cmd , "--project" , settings .ProjectID )
63+ moduleOpts = append (moduleOpts , testcontainers .WithCmdArgs ("--project" , settings .ProjectID ))
64+
65+ moduleOpts = append (moduleOpts , opts ... )
6666
67- container , err := testcontainers .GenericContainer (ctx , req )
67+ ctr , err := testcontainers .Run (ctx , img , moduleOpts ... )
6868 var c * Container
69- if container != nil {
70- c = & Container {Container : container , settings : settings }
69+ if ctr != nil {
70+ c = & Container {Container : ctr , settings : settings }
7171 }
7272 if err != nil {
73- return c , fmt .Errorf ("generic container : %w" , err )
73+ return c , fmt .Errorf ("run bigquery : %w" , err )
7474 }
7575
76- portEndpoint , err := c .PortEndpoint (ctx , "9050/tcp" , "http" )
76+ portEndpoint , err := c .PortEndpoint (ctx , defaultPort9050 , "http" )
7777 if err != nil {
7878 return c , fmt .Errorf ("port endpoint: %w" , err )
7979 }
0 commit comments