Skip to content

v0.4.0

Compare
Choose a tag to compare
@aelsabbahy aelsabbahy released this 23 Aug 14:21
7e70e27

Features

Thanks to all the contributors who have helped with this.

Summary:

  • Goss v0.4.X introduces some major enhancements to the matching logic allowing far more flexibility for asserts.
    • For example, can assert that the output of echo "3" is less than 5.
  • Introduces some minor breaking changes (see below)
  • v4 migration guide - Please submit issues/PRs if anything ewas missed in the migration guide

Matcher change

v4 introduced the ability to compare different types and more advanced string matching. See matchers section in the manual for more information.

For example:

command:
  echo_test:
    # command that outputs JSON, but this could be anything, http response, command output, etc
    exec: |
      echo '{"string_value": "15"}'
    exit-status: 0
    stdout:
      # advanced string parsing
      gjson:
        # extract "string_value"
        string_value:
          and:
            # The value is numerically <= 20 (auto type conversion)
            - le: 20
            # The value is numerically 15
            - 15
            # Equal does a strict check, the types have to match, hence string_value is "15" but not 15
            - equal: "15"
            - not: {equal: 15}

This conversion also allows treating an io.Reader (memory efficient line-by-line parsing) as a whole string (when compared with a string). This has the benefit of showing the full command output, which was a long-requested feature. For example:

$ cat goss.yaml
command:
  echo_test:
    exec: |
      echo 'hello world'
    exit-status: 0
    stdout: |
      goodbye world

$ goss v
.F

Failures/Skipped:

Command: echo_test: stdout:
Expected
    "hello world\n"
to equal
    "goodbye world\n"

Total Duration: 0.001s
Count: 2, Failed: 1, Skipped: 0

Breaking changes

  • Changed: file.Contains -> file.Contents
  • Changed: RPM Version is now full EVR (-qf "%|EPOCH?{%{EPOCH}:}:{}|%{VERSION}-%{RELEASE}), this opens the door for proper rpm version comparison in the future
  • For array matches (ex. user.Groups) duplicate entries will raise an error if they don't exist in the system.

In goss 3.X this would succeed:

user:
  xxx:
    exists: true
    groups:
        - foo
        - wheel
        - wheel

Now it will throw an error unless groups actually contain 2 copies of "wheel" in its response array from the system.

You can mimic the old behavior by modifying the test as follows:

user:
  xxx:
    exists: true
    groups:
      and:
        - contain-element: foo
        - contain-element: wheel
        - contain-element: wheel
  • Goss is more aware of types with goss v4, so ensure when doing string matching that integers and floats are surrounded by double quotes.

For example, this no longer works:

command:
  echo "123":
    exit-status: 0
    stdout:
    - 123

New way:

command:
  echo "123":
    exit-status: 0
    stdout:
    - "123"

Changes

  • Added: transforms support (closes #538)
    • Allows comparison of string to int, ex: ensuring a systctl output below/above a specific number (closes #220)
    • Allows JSON parsing/validation support (closes #578)
    • Allows comparing command output to a string, this will display the failed output on failure (closes #483)
    • -o include_raw will show the non-transformed value
  • Added: Some new matchers
    • equal matcher added to do strict type comparison (e.x. string to string)
    • contain-substring
    • have-patterns - This mimics the existing default behavior of file contents and command output
    • contain-elements - checks that an array value matches a set of matchers
  • Added: runlevels support for service
  • Added: option to sort output (closes #416)
  • Added: All resources now support key override (closes #518, closes #742)
  • Added: Use exit code 78 if test file is unparseable (closes #317)
  • Changed: removed alpha from non-linux binary names
  • Changed: StartTime is no longer calculated from goss start. Calculated from first test start, this allows accurate reporting when showing a cached result
  • Changed: Completely re-worked matchers and shared output logic
  • Changed: Cache test results in serve instead of output (closes #612)
  • Added: Significantly improved test coverage of matcher, output code
  • Changed: Doc to reference cat -E /proc/<PID>/comm to avoid whitespace issues (closes #762)
  • Changed: Removed file.Size from autoadd (closes #262)
  • Added: matcher.as-reader this allows the matcher string to behave as an io.Reader output. Can be useful for testing
  • Removed: json_online output format, use: goss v -f json -o oneline
  • Added: windows and darwin alpha binaries back in the release (#829)
  • Added: string diff support (#827)
  • Added: mount vfs-opts support (#826)