NixOS 101 Course / Section 6: NixOS integration tests
Premium

6.1 NixOS integration tests: what the test driver can do

Lesson 22 of 28 · 13:08

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

Video chapters

  1. 0:00 NixOS Integration Tests Overview
  2. 1:51 BitTorrent Multi-VM Test Example
  3. 5:43 Browser, Game, and VM-in-VM Test Cases
  4. 8:09 Writing a NixOS Test: Declarative Setup and Python Driver
  5. 10:21 How the Test Driver Runs VMs Efficiently
Transcript

NixOS Integration Tests Overview

0:00 Let's talk about NixOS integration tests in this section. This is my single most favorite killer feature of NixOS, because we can simply spin up multiple VMs in random network compositions with each other, and they are all expressed in NixOS configurations, and then you can have them stimulate each other. There's basically no limits. You can simulate all kinds of real-life like customer scenarios, and have your Nix packages and your NixOS modules play with each other the same way as they would be in production.

0:37 So let's have a look at what's there for us and what we can use from that. In general, nixpkgs contains more than 1,400 integration tests. So whatever you want to test, no matter how crazy your test scenario is, there will be some test that does at least something similar, so you can always inspire yourself and copy and paste from that. These tests are all in the nixpkgs repository under /nixos/tests, and they test everything, like browsers, games, databases, sharding for databases, stuff like that.

1:17 Even Kubernetes clusters can be quickly spin up in the VM, as VMs, and then tested. So that's extremely cool. My favorite test is this one here. So we basically define four machines. There's a machine called Tracker, Client 1 and 2, and Router. And we have like a blue network and a red network. So in the test driver, you can totally define multiple networks and how the VMs are connected.

The full transcript comes with the lesson.

About this lesson

NixOS integration tests start several machines, connect them in virtual networks, and check that your services work together just like in production. This lesson shows what the more than a thousand tests in nixpkgs do, the anatomy of a test, and why spinning up ten VMs takes seconds instead of minutes.

In this video

  • A BitTorrent test with four machines, two networks, and a router, explained step by step
  • Tests that click through browser windows, play games, and run VMs inside VMs
  • The two halves of every test: machine configurations and a Python script
  • How the driver, QEMU, and virtual network switches fit together in the build sandbox
  • Why NixOS test VMs are so much faster to rebuild than images from other tools

After this lesson

You know what integration tests can cover and how they are put together, and you are ready to write your first one.

Links: