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

inspec outputs full hash when testing ini style file option with [header] #1541

Closed
shoekstra opened this issue Mar 6, 2017 · 1 comment
Closed

Comments

@shoekstra
Copy link
Contributor

Description

When testing config in a mysql conf file with a [mysqld] header using the mysql_conf resource, the entire hash is returned in the test result instead of just the config option being tested. This could affect other INI style files too.

Instead of seeing:

  {"log_bin"=>"/var/log/mysql/mariadb-bin", "sync_binlog"=>"0"}
     ✔  ["sync_binlog"] should eq "0"

I would expect to see this (as you would without the ini style section header):

  MySQL Configuration
     ✔  sync_binlog should eq nil

InSpec and Platform Version

inspec 1.16.1 on CentOS Linux release 7.3.1611 (Core)

Replication Case

Create a test file (I used /tmp/my.cnf):

[mysqld]
log_bin = /var/log/mysql/mariadb-bin
sync_binlog = 0

Using InSpec shell:

inspec> describe mysql_conf('/tmp/my.cnf').mysqld do its(['sync_binlog']) { should eq '0' } end

Profile: inspec-shell
Version: (not specified)

  {"log_bin"=>"/var/log/mysql/mariadb-bin", "sync_binlog"=>"0"}
     ✔  ["sync_binlog"] should eq "0"

Test Summary: 1 successful, 0 failures, 0 skipped
@adamleff adamleff self-assigned this Mar 6, 2017
adamleff added a commit that referenced this issue Mar 6, 2017
When SimpleConfig parses a config file that has sections, such as a mysqld
config file, the values within that section are returned via a Hash. However,
we do not provide an easy way to write tests for those deep hash values:

```
describe mysql_conf('/tmp/my.cnf') do
  its('mysqld.expire_logs_days') { should cmp 10 }
end

  MySQL Configuration
     ∅  undefined method `expire_logs_days' for #<Hash:0x007fe463795a00>
```

This change provides a method-based accessor for Hashes that are built via
SimpleConfig.

```
describe mysql_conf('/tmp/my.cnf') do
  its('mysqld.expire_logs_days') { should cmp 10 }
end

  MySQL Configuration
     ✔  mysqld.expire_logs_days should cmp == 10
```

Fixes #1541 by changing the way the attributes are fetched.

Signed-off-by: Adam Leff <adam@leff.co>
@adamleff
Copy link
Contributor

adamleff commented Mar 6, 2017

@shoekstra when #1544 is merged and released, to correct this issue, you'll want to access the data as such:

describe mysql_conf('/tmp/my.cnf') do
  its('mysqld.expire_logs_days') { should cmp 10 }
end

  MySQL Configuration
     ✔  mysqld.expire_logs_days should cmp == 10

We'll look at #1543 separately.

adamleff added a commit that referenced this issue Mar 8, 2017
When SimpleConfig parses a config file that has sections, such as a mysqld
config file, the values within that section are returned via a Hash. However,
we do not provide an easy way to write tests for those deep hash values:

```
describe mysql_conf('/tmp/my.cnf') do
  its('mysqld.expire_logs_days') { should cmp 10 }
end

  MySQL Configuration
     ∅  undefined method `expire_logs_days' for #<Hash:0x007fe463795a00>
```

This change provides a method-based accessor for Hashes that are built via
SimpleConfig.

```
describe mysql_conf('/tmp/my.cnf') do
  its('mysqld.expire_logs_days') { should cmp 10 }
end

  MySQL Configuration
     ✔  mysqld.expire_logs_days should cmp == 10
```

Fixes #1541 by changing the way the attributes are fetched.

Signed-off-by: Adam Leff <adam@leff.co>
adamleff added a commit that referenced this issue Mar 15, 2017
When SimpleConfig parses a config file that has sections, such as a mysqld
config file, the values within that section are returned via a Hash. However,
we do not provide an easy way to write tests for those deep hash values:

```
describe mysql_conf('/tmp/my.cnf') do
  its('mysqld.expire_logs_days') { should cmp 10 }
end

  MySQL Configuration
     ∅  undefined method `expire_logs_days' for #<Hash:0x007fe463795a00>
```

This change provides a method-based accessor for Hashes that are built via
SimpleConfig.

```
describe mysql_conf('/tmp/my.cnf') do
  its('mysqld.expire_logs_days') { should cmp 10 }
end

  MySQL Configuration
     ✔  mysqld.expire_logs_days should cmp == 10
```

Fixes #1541 by changing the way the attributes are fetched.

Signed-off-by: Adam Leff <adam@leff.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants