Breadcrumbs

Test your custom generator bundle at the command line

Listing generators

You can list the generators exposed by your JSON bundle file (and their parameters) using the mettleci fabrication list command. You can use this command to list built-in generators …

Bash
$> mettleci fabrication list -include-internal -include-params
MettleCI Command Line (build 221)
(C) 2018-2022 Data Migrators Pty Ltd
fabrication list (v1.0-SNAPSHOT)
address.city_name
    Description: City name
address.country_code
    Description: Country code (ISO 3166-1)
    Parameters:
    - format                STRING                  ISO 3166-1 code in 2 (US) or 3 (USA) character format
address.country_name
    Description: Country name
address.county
    Description: County name
address.full_address
address.full_address_with_city_state
address.full_address_with_locality
    Parameters:
    - format                STRING                  ZIP or ZIP+4
address.state
    Description: State name or code
    Parameters:
    - format                STRING                  State name or code
address.street_name
address.street_number
etc.

… or list generators provided by a specific bundle file (or directory of files):

Bash
# List generators (and their parameters) defined in bands.json
$> mettleci fabrication list -path ./bands.json -include-params
MettleCI Command Line (build 221)
(C) 2018-2022 Data Migrators Pty Ltd
fabrication list (v1.0-SNAPSHOT)
band.album
    Description: A random album by a band
    Parameters:
    - band                  STRING    (Nullable)    Name of the band whose album to generate
band.member
    Description: A random member of a band
    Parameters:
    - band                  STRING    (Nullable)    Name of the band whose member to generate

Testing generators

Before uploading your bundle file to MettleCI Workbench you can test your generators at the command line using the mettleci fabrication test command which can be used to invoke built-in generators …

$> mettleci fabrication test -include-internal -generator address.full_address_with_city_state
MettleCI Command Line (build 221)
(C) 2018-2022 Data Migrators Pty Ltd
fabrication test (v1.0-SNAPSHOT)
5 Windsor Lane, Parker IN
Suite 37, 90 E 10th Street, Coral Gables DE
2 Avenue Street, Mount Pleasant SC
18 N Monroe Drive, Ashburn GA
Box 8, Lansing IL

… or call generators provided by a specific bundle file (or directory of files):

# A test with the no parameters specified, which provides values from any band
$> mettleci fabrication test -path ./bands.json -generator band.member
MettleCI Command Line (build 221)
(C) 2018-2022 Data Migrators Pty Ltd
fabrication test (v1.0-SNAPSHOT)
Keith Richards
Paul McCartney
Ringo Starr
Ronnie Wood
John Lennon

# A test with the the nullable 'band' parameter set to 'queen', providing values just for that band
$> mettleci fabrication test -path ./bands.json -generator band.member -Pband="queen"
MettleCI Command Line (build 221)
(C) 2018-2022 Data Migrators Pty Ltd
fabrication test (v1.0-SNAPSHOT)
Roger Taylor
Brian May
John Deacon
Brian May
Freddie Mercury

Creating a test script

You may find it useful to create a script to test your generators. The project maintainers of the public GitHub repository at https://github.mettleci.io/datafab are likely to approve any submissions to ythe repository quicker if they are accompanied by a test script. This script can be a simple or as complex as you wish, however the following example uses a loop to invoke the two generators for all permissible values of the band parameter.

#!/bin/bash
# bands bundle test script

# This script runs tests for the bands tutorial bundle using the mettleci tool.
shopt -s xpg_echo

export bundle=./bands.json
export bands=("beatles" "stones" "queen")

echo "\nListing available generators"
mettleci fabrication list -path $bundle -include-params

echo "\nRunning band.member for all bands"
mettleci fabrication test -path $bundle -generator band.member

echo "\nRunning band.album for all bands"
mettleci fabrication test -path $bundle -generator band.album

# Iterate over all potential parameter values, to test our generator expression and templates 
for band in "${bands[@]}"; do
    echo "\nRunning band.member for $band"
    mettleci fabrication test -path $bundle -generator band.member

    echo "\nRunning band.album for $band"
    mettleci fabrication test -path $bundle -generator band.album
done