Code Monkey home page Code Monkey logo

nginxtest's Introduction

NginxTest

This project provides some helpers to write functional tests against an Nginx server.

Motivation

The main motivation is to test Nginx/Lua scripts in an OpenResty environment. There's a Perl project to do this called Test::Nginx which is based on a light DSL to write the tests.

But I like writing plain Python tests better, especially since I can use WebTest to deal with all the calls against the Nginx server.

The NginxServer class

This project provides a class to drive an Nginx server. The class has two main method to start and stop a local Nginx server and takes care of the gory details.

When initialized, the class creates an Nginx configuration on the fly given a few options, and runs an Nginx server in a child process in a fresh directory.

Once the server is started, the stdout, stderr and access/errors logs are intercepted by the class so they can be asserted in the tests. The stop method kills the server.

Example of usage with WebTest:

import unittest2
from webtest import TestApp
from nginxtest.server import NginxServer


class TestMyNginx(unittest2.TestCase):

    def setUp(self):
        self.nginx = NginxServer()
        self.nginx.start()
        self.app = TestApp(self.nginx.root_url)

    def tearDown(self):
        self.nginx.stop()

    def testHello(self):
        resp = self.app.get('/')
        self.assertEqual(resp.status_int, 200)
        self.assertTrue('Welcome to nginx!' in resp.body)

Limitations

This project is very limited compared to Test::Nginx.

Stuff I'd like to add at some point:

  • Lua test coverage
  • XXX

nginxtest's People

Contributors

tarekziade avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.