Repository: goss-org/goss

Issue #743: render silently drops overlapping directives
Created: 2022-02-11T15:02:45Z
Describe the bug
Since the goss file format is a dictionary, overlapping keys do not work. This is described in the manual. However, when using multiple goss files, it is less obvious when this happens. Additionally I have a use case where it is helpful to break checks out into multiple logical categories that need to use the same directives to assert different things.
When render is used to combine files that have these types of overlaps, it does produce a valid file. But it silently drops values that appear first.
How To Reproduce
Below is a minimal example that reproduces the issue. Checking environment variable can be worked around using exec and providing distinct names. But splitting multiple checks for a specific file across files can never work.
$ cat a.yaml 
command:
  env:
    exit-status: 0
    stdout:
      - HOME=
file:
  /etc/passwd:
    exists: true
    owner: root

$ cat b.yaml 
command:
  env:
    exit-status: 0
    stdout:
      - PWD=
file:
  /etc/passwd:
    exists: true
    group: root

$ cat combined.yaml 
gossfile:
  a.yaml: {}
  b.yaml: {}

$ ./goss-linux-amd64 -g combined.yaml render
file:
  /etc/passwd:
    exists: true
    group: root
    contains: []
command:
  env:
    exit-status: 0
    stdout:
    - PWD=
    stderr: []
    timeout: 0

$ echo $?
0
Expected Behavior
In an idea world, I'd like the checks to be merged if they do not conflict (which is true in the example & my actual use case). However, I understand that is much more complicated to implement and might be surprising behavior to others.
Being more realistic, I'd expect render to exit with an error because it can't produce a valid goss file that accurately represents all of the files being combined.
Actual Behavior
render produces a valid goss file that does not include all of the checks from the combined files with no indication that this happened.
Environment:

Version of goss: v0.3.16

Duplicate issue #742: Ability to isolate tests
Created: 2022-02-11T12:47:28Z
Describe the feature:
Running industry benchmarks testing these can mean ensuring that different lines may occur within the same file each with a unique test. These will have differing titles, meta data dependent on the test that takes place.
I am sure this type of testing that may occur is not unique to this but the is an example i am working with.
In the example below
It appears the filename used by the file test is the unique identifier and therefore only take the output of the final test that runs. These benchmarks for each line could be in the same file or different files. Only the last benchmark that runs using the goss test reports the output.
e.g.
file:
/etc/somefilename:
{{ if .Vars.test1 }}
title: test1
exists: true
contains:
- test1_line
meta:
test1_ID
other_data
{{ end }}
{{ if .Vars.test2 }}
title: test2
exists: true
contains:
- test2_line
meta:
test2_ID
other_data
{{ end }}
If both are enabled the output would only show test2 information.
I have tested with different files, filenames etc.
Is there a better way that i can achieve this?
Describe the solution you'd like
Ability to run the different requirements on using a like goss test and control that is able to report back all the  output and the associated data
Describe alternatives you've considered
Rewrite each control with the command test and rename that command title to make them unique. But using the actual goss test is more efficient and less calls than running the command test.

Closing comment (2022-02-14T11:40:02Z): similar to #743