Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex file logic #107

Closed
oholiab opened this issue Jul 15, 2016 · 5 comments
Closed

Complex file logic #107

oholiab opened this issue Jul 15, 2016 · 5 comments

Comments

@oholiab
Copy link
Contributor

oholiab commented Jul 15, 2016

Hey, I'm attempting to write a test that will pass if:

  • the file doesn't exist
  • the file does exist and contains "foo"

Is this possible? I've tried various combinations of putting "or" at different levels in my goss.yaml but I'm getting the impression that it doesn't work like that... a simple test case with:

exists:
  or:
  - true
  - false

doesn't appear to work.

Is this something that is expected to work in the current version, and if not is it something that you consider to be within the scope of the project?

Thanks :)

@aelsabbahy
Copy link
Member

Interesting use case. Unfortunately, support for this does not currently exist in goss.

It would be easy to add this feature if it's defined as: "If resource does not exist, skip ALL other tests."

If the feature requested is to do more complex logic like: "If the file is mode 0755, then ensure content X otherwise ensure content Y" that might be much more complex.

@oholiab
Copy link
Contributor Author

oholiab commented Jul 15, 2016

I'd be fine with "skip if file does not exist" :)

Any more complex logic than that and I would agree that it's totally out of
scope and I should just write some Go ;)
On 15 Jul 2016 17:14, "Ahmed Elsabbahy" [email protected] wrote:

Interesting use case. Unfortunately, support for this does not currently
exist in goss.

It would be easy to add this feature if it's defined as: "If resource does
not exist, skip ALL other tests."

If the feature requested is to do more complex logic like: "If the file is
mode 0755, then ensure content X otherwise ensure content Y" that might be
much more complex.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#107 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAxthnra4_nbwK-WHE_0zCoXnpmGhq7bks5qV7HygaJpZM4JNht3
.

@taurus-forever
Copy link

JFYI, we have moved all such logic on the layer before the goss execution.

We are using templates toolkit to build the server specific goss.json file (IP, services, server role, server configuration) and then trigger goss with plain goss.json, like:

> cat /etc/.../goss.json 
{
    "gossfile": {
        "01_running-processes.json": {},
        "01_hostname-and-interfaces.json": {},
        "02_disk-free.json": {},
        "03_files_availability.json": {},
        "03_no-cores.json": {},
        "03_open_ports.json": {},
        "04_template_files.json": {},
        "05_system_users.json": {},
        "06_system_packages.json": {},
        "07_system_service.json": {},
        "08_system_ports.json": {},
        "09_system_dns.json": {},
        "10_sites_ok.json": {},
        "99_dummy.json": {}
    }
}

You can find our repo here https://github.com/sipwise/system-tests ;-)
Hope it will help you a bit!

@aelsabbahy
Copy link
Member

So, this will have to wait for the next release of goss. I had some time to work on it today, but prioritized fixing bugs over enhancements.

This change is a bit more work than I initially thought since currently tests have only a "Successful" boolean. I need to add a "Status" or "Result" which allows for success, failed, skipped and update the outputs to support that format.

aelsabbahy added a commit that referenced this issue Jul 24, 2016
* Skip optional tests for non existing system resources
* Skipped tests do not count as a failure on their own, but are almost
always accompanied with a failing test, the only exception is when the
exists test is made optional through matchers (see #107):
```yaml
exists:
  or:
  - true
  - false
```
* Undefined required attributes will now result in an error
aelsabbahy added a commit that referenced this issue Jul 24, 2016
* Skip optional tests for non existing system resources
* Skipped tests do not count as a failure on their own, but are almost
always accompanied with a failing test, the only exception is when the
exists test is made optional through matchers (see #107):
```yaml
exists:
  or:
  - true
  - false
```
* Undefined required attributes will now result in an error
@aelsabbahy
Copy link
Member

Released in v0.1.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants