|
| 1 | +#!/usr/bin/env bats |
| 2 | +# |
| 3 | +# Copyright (c) 2015 by Delphix. All rights reserved. |
| 4 | +# |
| 5 | + |
| 6 | +# |
| 7 | +# Test the npmjs-proxy app, Sinopia. |
| 8 | +# |
| 9 | + |
| 10 | +# A node package to attempt to install through our proxy. |
| 11 | +NODE_PACKAGE=statsd |
| 12 | + |
| 13 | +setup() { |
| 14 | + apt-get install -y curl npm |
| 15 | + npm set registry http://localhost:4873/ |
| 16 | +} |
| 17 | + |
| 18 | +@test "Accessing the npmjs vhost should return HTTP 200" { |
| 19 | + run curl -sS -I -H 'Host: npm' http://localhost |
| 20 | + [ "$status" -eq 0 ] |
| 21 | + [[ "$output" =~ "HTTP/1.1 200 OK" ]] |
| 22 | +} |
| 23 | + |
| 24 | +@test "Accessing the npmjs-proxy vhost should reveal the back-end app's name" { |
| 25 | + run curl -sS -I -H 'Host: npm' http://localhost |
| 26 | + [ "$status" -eq 0 ] |
| 27 | + [[ "$output" =~ "X-Powered-By: Sinopia" ]] |
| 28 | +} |
| 29 | + |
| 30 | +@test "Downloading & installing a Node package through our npmjs proxy should succeed" { |
| 31 | + run npm install $NODE_PACKAGE |
| 32 | + [ "$status" -eq 0 ] |
| 33 | + echo $output |
| 34 | + regex="npm http (200|304) http://localhost:4873/$NODE_PACKAGE" |
| 35 | + [[ "$output" =~ $regex ]] |
| 36 | +} |
| 37 | + |
| 38 | +# |
| 39 | +# Kill the Sinopia container and restart it with its networking broken by |
| 40 | +# giving it bad DNS server settings. With npmjs.org unavailable but our |
| 41 | +# cache already populated, the download of the previous Node package should |
| 42 | +# still succeed. |
| 43 | +# |
| 44 | + |
| 45 | +@test "We should be able to install cached Node packages when the Sinopia container's networking backend is broken" { |
| 46 | + docker kill sinopia |
| 47 | + docker rm sinopia |
| 48 | + docker run -d --name sinopia -p 4873:4873 --dns=1.1.1.1 -v /opt/npmjs-server:/sinopia/storage rnbwd/sinopia |
| 49 | + # Give the app a few seconds to load |
| 50 | + sleep 5 |
| 51 | + |
| 52 | + run npm install $NODE_PACKAGE |
| 53 | + [ "$status" -eq 0 ] |
| 54 | + regex="npm http (200|304) http://localhost:4873/$NODE_PACKAGE" |
| 55 | + [[ "$output" =~ $regex ]] |
| 56 | + |
| 57 | + # restart the container with networking un-broken |
| 58 | + docker kill sinopia |
| 59 | + docker rm sinopia |
| 60 | + docker run -d --name sinopia -p 4873:4873 -v /opt/npmjs-server:/sinopia/storage rnbwd/sinopia |
| 61 | +} |
0 commit comments