Jelajahi Sumber

Merge pull request #46 from dom111/master-topic-28-additional_test_files_in_docker

Adding in additional test files for the Docker test environment
Dom Hastings 6 tahun lalu
induk
melakukan
273cf7dc96
4 mengubah file dengan 126 tambahan dan 22 penghapusan
  1. 0 0
      src/webdav-min.js
  2. 6 6
      src/webdav.js
  3. 60 8
      test/run-cdn.sh
  4. 60 8
      test/run-local.sh

File diff ditekan karena terlalu besar
+ 0 - 0
src/webdav-min.js


+ 6 - 6
src/webdav.js

@@ -62,10 +62,10 @@
             demoText = 'The quick brown fox jumps over the lazy dog. 0123456789<br/>Aa Bb Cc Dd Ee Ff Gg Hh Ii Jj Kk Ll Mm Nn Oo Pp Qq Rr Ss Tt Uu Vv Ww Xx Yy Zz';
 
             if (!$('[data-path="' + (file.path + file.name) + '"]').is('style')) {
-              $('body').appendChild('<style type="text/css" data-path="' + (file.path + file.name) + '">@font-face{font-family:"' + fontName + '";src:url("' + file.path + file.name + '") format("' + (formats[extension] || extension) + '")}</style>');
+              $('body').append('<style type="text/css" data-path="' + (file.path + file.name) + '">@font-face{font-family:"' + fontName + '";src:url("' + file.path + file.name + '") format("' + (formats[extension] || extension) + '")}</style>');
             }
 
-            $.featherlight('<h1 style="font-family:"' + fontName + '">' + file.name + '</h1><p style="font-family:\'' + fontName + '\';font-size:1.5em">' + demoText + '</p><p style="font-family:\'' + fontName + '\'">' + a + '</p><p style="font-family:\'' + fontName + '\'"><strong>' + demoText + '</strong></p><p style="font-family:\'' + fontName + '\'"><em>' + demoText + '</em></p><p><a href="' + file.path + file.name + '" style="display:inline-block;padding:.5em;background:#000;font-family:sans-serif;border-radius:.5em;color:#fff">Download</a></p>');
+            $.featherlight('<h1 style="font-family:\'' + fontName + '\'">' + file.name + '</h1><p style="font-family:\'' + fontName + '\';font-size:1.5em">' + demoText + '</p><p style="font-family:\'' + fontName + '\'">' + demoText + '</p><p style="font-family:\'' + fontName + '\'"><strong>' + demoText + '</strong></p><p style="font-family:\'' + fontName + '\'"><em>' + demoText + '</em></p><p><a href="' + file.path + file.name + '" style="display:inline-block;padding:.5em;background:#000;font-family:sans-serif;border-radius:.5em;color:#fff">Download</a></p>');
 
             event.preventDefault();
           }
@@ -78,15 +78,16 @@
                     $container = $('<pre class="prettyprint"></pre>');
                     $.ajax(url, {
                       complete: function(response, status) {
-                        if ( status !== "error" ) {
+                        if (status !== "error") {
                           $container.text(response.responseText);
                           deferred.resolve($container);
 
                           // prettify the code
                           PR.prettyPrint();
                         }
-
-                        deferred.fail();
+                        else {
+                          deferred.fail();
+                        }
                       }
                     });
 
@@ -386,7 +387,6 @@
     _updateDisplay = function() {
       document.title = decodeURIComponent(_path) + ' - ' + window.location.host;
 
-      _sortFiles();
       _renderFiles();
     },
 

+ 60 - 8
test/run-cdn.sh

@@ -1,23 +1,75 @@
 #!/bin/bash
 
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
+dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )";
 
 if [ "$(docker ps -a | grep webdav-js-app)" ]; then
-	docker stop webdav-js-app
-	docker rm webdav-js-app
+    docker stop webdav-js-app > /dev/null;
+    docker rm webdav-js-app > /dev/null;
 fi
 
+# additional test files
+tmpDir=$(cd "$dir/../tmp" && pwd);
+if [[ ! -d $tmpDir ]]; then
+    mkdir $tmpDir;
+fi
+
+volumes="-v $dir/../:/var/www/webdav-js:ro -v $dir/../examples/apache-directory-list/webdav.conf:/etc/apache2/sites-enabled/webdav.conf:ro -v $dir/../src/webdav.js:/var/www/html/source.js:ro -v $dir/../assets/css/style.css:/var/www/html/style.css:ro";
+
+# Hide missing ServerName error
+if [[ ! -e $tmpDir/server.conf ]]; then
+    echo 'ServerName localhost' > $tmpDir/server.conf;
+fi
+
+volumes="$volumes -v $tmpDir/server.conf:/etc/apache2/sites-enabled/server.conf:ro";
+
+# get random images for testing
+echo -n "Downloading images... ";
+
+for (( i = 0; i < 10; i++ )); do
+    if [[ ! -e "$tmpDir/$i.jpg" ]]; then
+        curl -sL -o "$tmpDir/$i.jpg" "https://source.unsplash.com/random/";
+    fi
+
+    volumes="$volumes -v $tmpDir/$i.jpg:/var/www/html/image_$i.jpg:ro";
+done
+
+echo 'Done!';
+
+# get fonts for testing
+echo -n "Downloading fonts... ";
+
+for font in notoserif/NotoSerif-Regular.ttf unlock/Unlock-Regular.ttf blackandwhitepicture/BlackAndWhitePicture-Regular.ttf indieflower/IndieFlower-Regular.ttf; do
+    fontName="$(basename $font)";
+
+    if [[ ! -e "$tmpDir/$fontName" ]]; then
+        curl -s -o "$tmpDir/$fontName" "https://cdn.jsdelivr.net/gh/google/fonts/ofl/$font";
+    fi
+
+    volumes="$volumes -v $tmpDir/$fontName:/var/www/html/$fontName:ro";
+done
+
+echo 'Done!';
+
+# get video for testing
+echo -n "Downloading video... ";
+
+if [[ ! -e "$tmpDir/video.mp4" ]]; then
+    curl -s -o "$tmpDir/video.mp4" "http://techslides.com/demos/sample-videos/small.mp4";
+fi
+
+volumes="$volumes -v $tmpDir/video.mp4:/var/www/html/video.mp4:ro";
+echo 'Done!';
+
 docker run -dit \
 --name webdav-js-app \
 -p 8080:80 \
--v $DIR/../examples/apache-directory-list/webdav.conf:/etc/apache2/sites-enabled/webdav.conf:ro \
--v $DIR/../:/var/www/webdav-js:ro \
-webdav-js sleep infinity
+$volumes \
+webdav-js sleep infinity;
 
 docker exec -it webdav-js-app /bin/bash -c "\
 chown www-data -R /var/www/html 2> /dev/null; \
 rm /etc/apache2/sites-enabled/000-default.conf; \
 apachectl start || apachectl restart \
-"
+";
 
-echo 'This can be tested on http://localhost:8080'
+echo 'This can be tested on http://localhost:8080';

+ 60 - 8
test/run-local.sh

@@ -1,23 +1,75 @@
 #!/bin/bash
 
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
+dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )";
 
 if [ "$(docker ps -a | grep webdav-js-app)" ]; then
-	docker stop webdav-js-app
-	docker rm webdav-js-app
+    docker stop webdav-js-app > /dev/null;
+    docker rm webdav-js-app > /dev/null;
 fi
 
+# additional test files
+tmpDir=$(cd "$dir/../tmp" && pwd);
+if [[ ! -d $tmpDir ]]; then
+    mkdir $tmpDir;
+fi
+
+volumes="-v $dir/../:/var/www/webdav-js:ro -v $dir/../examples/apache-directory-list-local/webdav.conf:/etc/apache2/sites-enabled/webdav.conf:ro -v $dir/../src/webdav.js:/var/www/html/source.js:ro -v $dir/../assets/css/style.css:/var/www/html/style.css:ro";
+
+# Hide missing ServerName error
+if [[ ! -e $tmpDir/server.conf ]]; then
+    echo 'ServerName localhost' > $tmpDir/server.conf;
+fi
+
+volumes="$volumes -v $tmpDir/server.conf:/etc/apache2/sites-enabled/server.conf:ro";
+
+# get random images for testing
+echo -n "Downloading images... ";
+
+for (( i = 0; i < 10; i++ )); do
+    if [[ ! -e "$tmpDir/$i.jpg" ]]; then
+        curl -sL -o "$tmpDir/$i.jpg" "https://source.unsplash.com/random/";
+    fi
+
+    volumes="$volumes -v $tmpDir/$i.jpg:/var/www/html/image_$i.jpg:ro";
+done
+
+echo 'Done!';
+
+# get fonts for testing
+echo -n "Downloading fonts... ";
+
+for font in notoserif/NotoSerif-Regular.ttf unlock/Unlock-Regular.ttf blackandwhitepicture/BlackAndWhitePicture-Regular.ttf indieflower/IndieFlower-Regular.ttf; do
+    fontName="$(basename $font)";
+
+    if [[ ! -e "$tmpDir/$fontName" ]]; then
+        curl -s -o "$tmpDir/$fontName" "https://cdn.jsdelivr.net/gh/google/fonts/ofl/$font";
+    fi
+
+    volumes="$volumes -v $tmpDir/$fontName:/var/www/html/$fontName:ro";
+done
+
+echo 'Done!';
+
+# get video for testing
+echo -n "Downloading video... ";
+
+if [[ ! -e "$tmpDir/video.mp4" ]]; then
+    curl -s -o "$tmpDir/video.mp4" "http://techslides.com/demos/sample-videos/small.mp4";
+fi
+
+volumes="$volumes -v $tmpDir/video.mp4:/var/www/html/video.mp4:ro";
+echo 'Done!';
+
 docker run -dit \
 --name webdav-js-app \
 -p 8080:80 \
--v $DIR/../examples/apache-directory-list-local/webdav.conf:/etc/apache2/sites-enabled/webdav.conf:ro \
--v $DIR/../:/var/www/webdav-js:ro \
-webdav-js sleep infinity
+$volumes \
+webdav-js sleep infinity;
 
 docker exec -it webdav-js-app /bin/bash -c "\
 chown www-data -R /var/www/html 2> /dev/null; \
 rm /etc/apache2/sites-enabled/000-default.conf; \
 apachectl start || apachectl restart \
-"
+";
 
-echo 'This can be tested on http://localhost:8080'
+echo 'This can be tested on http://localhost:8080';

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini