NixOS 101 Course / Section 6: NixOS integration tests
Premium

6.6 Exercise: write an integration test for your NixOS service

Lesson 27 of 28 · 22:06

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

Video chapters

  1. 0:00 Intro to testing Hello as a Service
  2. 2:12 Set up the minimal test driver example
  3. 5:31 Run the first local service test
  4. 8:10 Add a client VM and test over the network
  5. 12:22 Improve assertions and wait for service readiness
  6. 17:28 Parameterize the port and finalize the test
Transcript

Intro to testing Hello as a Service

0:00 All right, so after we had a look at how the test driver works, what it can do, and there are some more features that we're going to talk about. But first things first, let's take the most important features and get our hands dirty with writing our own test for the Hello as a Service module that we wrote earlier. So it was kind of a bit annoying that we could kind of change the Hello as a Service module, run it ourselves, and then check if it works, if we can do that automatically with a test driver, right? So let's go.

0:31 The idea here is that we download this zip ball, which creates a minimal test that runs Hello as a local application. And then we copy our Hello as a Service dot nix and configuration dot nix files from the solution from before. So we can I'm linking the download link of the solution of the old exercise here so that you have everything at your disposal. And then we combine that. The idea is to have one VM that serves Hello as a Service and another VM that would be the client that tries to connect and get the Hello as a Service output.

1:12 And yeah, for that, we will need multiple things. But let's first have a look at how the unpacked folder looks like. So I already downloaded it and we basically have the default dot nix file and the test dot nix file. I copied configuration dot nix and Hello as a Service nix from the exercise before. And let's see what we have. The default nix file is boring. It simply does the typical boilerplate.

The full transcript comes with the lesson.

About this lesson

Practice time. You write a test for the Hello as a Service module from earlier in the course: one machine runs the service, and a client fetches its output over the network. Then we polish the test until it is free of race conditions and hard-coded values.

In this video

  • Turning a single-machine starter test into a client and server setup
  • Assertions that tell you what went wrong at first glance
  • Two wait calls that look redundant and how they prevent flaky CI failures
  • Passing values from the Nix configuration into the Python test script

After this lesson

You have a solid test for your own service. You know some tricks that keep tests reliable when they run on a busy CI machine.

Builds on: Exercise: add an openFirewall option to your service module (2.8)

Links: