
    T&                         d dl Z d dlZd dlZd dlmZ e j
                  j                  e j
                  j                  e            Z G d dej                        Z
edk(  r ej                          yy)    N)testutilc                   v     e Zd ZdZd Zd Z fdZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Z xZS )RuntimeTestCasez1Tests for the PHP external runtime fingerprinter.c                 ,    t        j                  d      S )Na              # Copyright 2015 Google Inc. All Rights Reserved.
            #
            # Licensed under the Apache License, Version 2.0 (the "License");
            # you may not use this file except in compliance with the License.
            # You may obtain a copy of the License at
            #
            #    http://www.apache.org/licenses/LICENSE-2.0
            #
            # Unless required by applicable law or agreed to in writing, software
            # distributed under the License is distributed on an "AS IS" BASIS,
            # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
            # See the License for the specific language governing permissions and
            # limitations under the License.

            textwrapdedentselfs    -platform/ext-runtime/php/test/runtime_test.pylicensezRuntimeTestCase.license   s        	    c                 ,    t        j                  d      S )Na/              # Dockerfile extending the generic PHP image with application files for a
            # single application.
            FROM gcr.io/google-appengine/php:latest

            # The Docker image will configure the document root according to this
            # environment variable.
            r   r
   s    r   preamblezRuntimeTestCase.preamble.   s        	r   c                 @    t         | _        t        t        |           y N)RUNTIME_DEF_ROOTruntime_def_rootsuperr   setUp)r   	__class__s    r   r   zRuntimeTestCase.setUp8   s     0ot*,r   c                     t        | j                  |            5 }|j                         cd d d        S # 1 sw Y   y xY wr   )open	full_pathread)r   filenamefs      r   file_contentszRuntimeTestCase.file_contents<   s*    $..*+q668 ,++s   5>c                    | j                  dd       | j                  | j                                | j                  t        j                  j                  | j                  d                   | j                  t        j                  j                  | j                  d                   | j                  t        j                  j                  | j                  d                   y )Nz
index.htmlindexapp.yaml
Dockerfile.dockerignore)
write_fileassertFalsegenerate_configsospathexistsr   r
   s    r   test_generate_without_php_filesz/RuntimeTestCase.test_generate_without_php_files@   s    g...01z(BCD|(DEF(GHIr   c                    | j                  dd       | j                          | j                  d      }| j                  d|       | j                  d|       | j                  d|       | j	                  d|       | j                  t        j                  j                  | j                  d                   | j                  t        j                  j                  | j                  d	                   y )
N	index.phpr    r!   runtime: php

env: flex
#runtime_config:
  document_root: .

entrypointr"   r#   )
r$   r&   r   assertInassertNotInr%   r'   r(   r)   r   r   app_yamls     r   test_generate_with_php_filesz,RuntimeTestCase.test_generate_with_php_filesI   s    W-%%j1&1mX.=xHx0|(DEF(GHIr   c                    | j                  dd       | j                          | j                  d      }| j                  d|       | j                  d|       | j                  d|       | j	                  t
        j                  j                  | j                  d                   | j	                  t
        j                  j                  | j                  d                   y	)
zTest generate_config_data with a .php file.

        Checks app.yaml contents, app.yaml is written to disk, and
        Dockerfile and .dockerignore not in the directory.
        r,   r    r!   r-   r.   r/   r"   r#   N)	r$   generate_config_datar   r1   r%   r'   r(   r)   r   r3   s     r   %test_generate_with_php_files_no_writez5RuntimeTestCase.test_generate_with_php_files_no_writeV   s     	W-!!#%%j1&1mX.=xH|(DEF(GHIr   c                 F   | j                  dd       | j                  d       | j                  d      }| j                  || j	                         t        j                  d      z          | j                  d| j                         t        j                  d      z          y )	Nr,   r    Tcustomr"   /            ENV DOCUMENT_ROOT /app
            r#   o            .dockerignore
            Dockerfile
            .git
            .hg
            .svn
            )	r$   r&   r   assertEqualr   r   r	    assert_file_exists_with_contentsr   )r   
dockerfiles     r   test_generate_custom_runtimez,RuntimeTestCase.test_generate_custom_runtimeg   s    W-T*''5
T]]_x H 8 & 	 	--LLNX__ .  	r   c                 (   | j                  dd       | j                  d      }| j                  |d| j                         t	        j
                  d      z          | j                  |d| j                         t	        j
                  d      z          y	)
z/Tests generate_config_data with custom runtime.r,   r    Tr:   r"   r<   r#   r=   Nr$   r7   #assert_genfile_exists_with_contentsr   r   r	   r   r   	cfg_filess     r   %test_generate_custom_runtime_no_writez5RuntimeTestCase.test_generate_custom_runtime_no_writez       W---T-:	00MMOhoo /  	 	00LLNX__ .  		r   c                 F   | j                  dd       | j                  d       | j                  d      }| j                  |t	        j
                  d             | j                  d      }| j                  || j                         t	        j
                  d      z          y )	Nr,   r    Tdeployr"   aR              # Dockerfile extending the generic PHP image with application files for a
            # single application.
            FROM gcr.io/google-appengine/php:latest

            # The Docker image will configure the document root according to this
            # environment variable.
            ENV DOCUMENT_ROOT /app
            r#   r=   )r$   r&   r   r>   r   r	   r   )r   r@   dockerignores      r   test_generate_with_deployz)RuntimeTestCase.test_generate_with_deploy   s    W-T*''5
X__ 6 & 	 ))/:t||~ I 9 ( 	r   c                 (   | j                  dd       | j                  d      }| j                  |d| j                         t	        j
                  d      z          | j                  |d| j                         t	        j
                  d      z          y	)
z,Tests generate_config_data with deploy=True.r,   r    TrJ   r"   r<   r#   r=   NrC   rE   s     r   "test_generate_with_deploy_no_writez2RuntimeTestCase.test_generate_with_deploy_no_write   rH   r   c                    | j                  dd       t        j                  ddid      }| j                  d|       | j	                  d	      }| j                  || j                         t        j                  d
      z          | j	                  d      }| j                  || j                         t        j                  d      z          y )Nr,   r    document_root	wordpress["/bin/bash", "my-cmd.sh"]runtime_configr0   TrK   appinfor"               ENV DOCUMENT_ROOT /app/wordpress

            # Allow custom CMD
            CMD ["/bin/bash", "my-cmd.sh"]
            r#   r=   )
r$   r   AppInfoFaker&   r   r>   r   r   r	   r   )r   rW   r@   rL   s       r   #test_generate_with_existing_appinfoz3RuntimeTestCase.test_generate_with_existing_appinfo   s    W-&& /=79 	T7;''5
T]]_x H 8 & 	 ))/:t||~ I 9 ( 	r   c                 \   | j                  dd       t        j                  ddid      }| j                  d|      }| j	                  |d	| j                         t        j                  d
      z          | j	                  |d| j                         t        j                  d      z          y)z-Tests generate_config_data with fake appinfo.r,   r    rQ   rR   rS   rT   TrV   r"   rX   r#   r=   N)	r$   r   rY   r7   rD   r   r   r	   r   r   rW   rF   s      r   ,test_generate_with_existing_appinfo_no_writez<RuntimeTestCase.test_generate_with_existing_appinfo_no_write   s    W-&& /=79 --T7-K	00MMOhoo /  	 	00LLNX__ .  		r   c                    | j                  dd       t        j                  ddiddg      }| j                  d|	       | j	                  d
      }| j                  || j                         t        j                  d      z          y )Nr,   r    rQ   rR   	/bin/bash	my-cmd.shrT   TrV   r"   rX   )	r$   r   rY   r&   r   r>   r   r   r	   )r   rW   r@   s      r   #test_generate_with_array_entrypointz3RuntimeTestCase.test_generate_with_array_entrypoint   s    W-&& /='57 	T7;''5
T]]_x H 8 & 	r   c                     | j                  dd       t        j                  ddiddg      }| j                  d|	      }| j	                  |d
| j                         t        j                  d      z          y)z4Tests generate_config_data with an array entrypoint.r,   r    rQ   rR   r_   r`   rT   TrV   r"   rX   N)r$   r   rY   r7   rD   r   r   r	   r\   s      r   ,test_generate_with_array_entrypoint_no_writez<RuntimeTestCase.test_generate_with_array_entrypoint_no_write  sy    W-&& /='57 --T7-K	00MMOhoo /  	r   )__name__
__module____qualname____doc__r   r   r   r   r*   r5   r8   rA   rG   rM   rO   rZ   r]   ra   rc   __classcell__)r   s   @r   r   r      sT    ;$-JJJ"&.0.0:r   r   __main__)r'   r   unittestgae_ext_runtimer   r(   dirname__file__r   TestBaser   rd   main r   r   <module>rq      sb     
   $77??277??8#<= {h'' {z zHMMO r   