Testing Files Generator
English

Getting started

Five minutes from an installed tfg to a set of test files your tests can rely on. Every command here runs as it is, on Windows, macOS and Linux. If you have not installed it yet, start with Install.

  1. Make one file of an exact size

    Name the format, the size and the folder. This makes one PNG of exactly two megabytes:

    tfg generate --format png --size 2mb --out ./out
    1 file in 1 target, 2 097 152 B total

    Sizes count in 1024s, the way a file manager does, so 2mb is 2 097 152 bytes. A plain byte count works too. The PNG opens in any picture viewer, and beside it is manifest.json, the record of what the run made and how your system should react to each file.

  2. Make many files at once

    Ten thousand log files, each between one and eight kilobytes. The sizes are drawn from the seed, so the same command gives the same set tomorrow and on any other machine:

    tfg generate --format log --size-range 1kb-8kb --count 10000 --out ./logs

    Give each run its own folder. The manifest is the only record of what a run wrote, so a second run into a folder that holds one is refused rather than written over it. Add --number-if-taken to put the second run beside the first instead.

  3. Check the files, then remove them

    verify says whether every file is still there and still the same. cleanup removes the files the manifest lists and nothing else. Without --yes it only says what it would remove:

    tfg verify ./out/manifest.json
    tfg cleanup ./out/manifest.json
    tfg cleanup ./out/manifest.json --yes
    out matches ./out/manifest.json: 1 file checked
    1 file would be removed from out:
      remove files_0001.png
    Nothing was removed. Run the same command with --yes to remove them.
    1 file removed from out
  4. Say what your system should do with the files

    A test file is only half a test. The other half is what should happen to it. Write it on the command line and the manifest carries it beside every file:

    tfg generate --format pdf --size 12mb --expected reject --expected-reason size_limit --out ./too-big

    For a size limit, the size-boundaries preset makes the whole set at once: files just under the limit, at it and just over it, each with its expected outcome:

    tfg generate --preset size-boundaries --limit 10mb --format pdf --out ./limit
  5. Make a file that is broken on purpose

    A damaged file still has the size you asked for, and the manifest expects your system to turn it away. tfg damage lists the damages this build has:

    tfg generate --format png --size 2mb --damage zero-head --out ./broken
  6. Turn the run into a recipe

    Once the set is right, write it down. A recipe is a short YAML file you commit beside your tests, so the files never have to be committed: anyone rebuilds them, byte for byte.

    # fixtures.yaml
    version: 1
    seed: 7741
    
    targets:
      - id: invoices
        format: pdf
        count: 25
        size: 300kb
        name: invoice_{index:04}.pdf
        expected: accept
    
      - id: too_big
        format: pdf
        size: 12mb
        expected:
          outcome: reject
          reason: size_limit
    
    output:
      dir: ./fixtures
    tfg validate fixtures.yaml
    tfg generate fixtures.yaml

    validate checks the recipe and writes nothing. Every key is in the recipe reference, and the recipe gallery has ready recipes to start from.

Where to go next