Git Product home page Git Product logo

docker-unit-testing's Introduction

PrivateBin unit testing docker image

PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted and decrypted in the browser using 256bit AES in Galois Counter mode.

This repository contains the Dockerfile and resources needed to create a docker image with a pre-installed phpunit & mocha. The image is based on the docker hub php:7.0-cli-alpine image, extended with the GD module & nodejs. Run the container with your local PrivateBin repository as a read-only volume and it will run both the PHP and JavaScript test suites in parallel and return the results.

Running the image

Assuming you have docker successfully installed and internet access, you can fetch and run the image from the docker hub like this:

docker run --rm --read-only -v ~/PrivateBin:/srv:ro --tmpfs /tmp privatebin/unit-testing

The parameters in detail:

  • -v ~/PrivateBin:/srv:ro - Replace ~/PrivateBin with the location of the checked out PrivateBin repository on your machine. It is recommended to mount it read-only, which guarantees that your repository isn't damaged by a accidentally destructive test case in it.
  • --read-only - This image supports running in read-only mode. Only /tmp may be written into.
  • -rm - Remove the container after the run. This safes you doing a cleanup on your docker environment, if you run the image frequently.

Note: Inside the container, the first thing that will be done is to copy your repository into /tmp/repo. The unit tests are then run in this copy. While this slows things done a bit, it ensures that a test script inside your repository can't accidentally delete objects in it.

Running just phpunit or mocha

Optionally you can run just the PHP or Javascript unit tests by specifying the optional parameter:

docker run --rm --read-only -v ~/PrivateBin:/srv:ro --tmpfs /tmp privatebin/unit-testing phpunit
docker run --rm --read-only -v ~/PrivateBin:/srv:ro --tmpfs /tmp privatebin/unit-testing mocha

You may also limit the test execution to a single test file to speed up repeats

docker run --rm --read-only -v ~/PrivateBin:/srv:ro --tmpfs /tmp privatebin/unit-testing phpunit ConfigurationTest.php
docker run --rm --read-only -v ~/PrivateBin:/srv:ro --tmpfs /tmp privatebin/unit-testing mocha test/Helper.js

Rolling your own image

To reproduce the image, run:

docker build -t privatebin/unit-testing .

Behind the scenes

Since both unit test frameworks process the test cases linearly, both use only one CPU core. Nowadays most system have more then one, so the entrypoint script launches mocha in the background and phpunit in the foreground. On systems with 2 or more CPUs they can therefore run in parallel. On a recently modern amd64 CPU phpunit should take about 14s to run and mocha around 45s, hence its output gets displayed after phpunit.

docker-unit-testing's People

Contributors

elrido avatar simonrupf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.