File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ #
2
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
3
+ # not use this file except in compliance with the License. You may obtain
4
+ # a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
+ # License for the specific language governing permissions and limitations
12
+ # under the License.
13
+ from testcontainers .core .generic import GenericContainer
14
+
15
+
16
+ class NginxContainer (GenericContainer ):
17
+ def __init__ (self , image = "nginx:latest" , port_to_expose = 80 ):
18
+ super (NginxContainer , self ).__init__ (image )
19
+ self .port_to_expose = port_to_expose
20
+ self .with_exposed_ports (self .port_to_expose )
Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+ from testcontainers .nginx import NginxContainer
4
+
5
+
6
+ def test_docker_run_nginx ():
7
+ nginx_container = NginxContainer ("nginx:1.13.8" )
8
+ with nginx_container as nginx :
9
+ port = nginx .port_to_expose
10
+ url = "http://{}:{}/" .format (nginx .get_container_host_ip (),
11
+ nginx .get_exposed_port (port ))
12
+ r = requests .get (url )
13
+ assert (r .status_code == 200 )
14
+ assert ('Welcome to nginx!' in r .text )
You can’t perform that action at this time.
0 commit comments