bloomberg / chef-umami

A tool to automatically generate test code for Chef cookbooks and policies.
Apache License 2.0
33 stars 10 forks source link

Treat arrays like arrays, not strings #15

Open RyanFrantz opened 7 years ago

RyanFrantz commented 7 years ago

When writing tests where a parameter is an array, we end up writing out a string version of the array. This breaks tests like package. Here are some example failures related to this issue:

Arrays should be treated like arrays, not strings:

  9) blp-chef-workstation::_os installs package "mysql-connector-python"
     Failure/Error: expect(chef_run).to install_package('mysql-connector-python').with(package_name: '["mysql-connector-python"]')

       expected "yum_package[mysql-connector-python]" to have parameters:

         package_name "[\"mysql-connector-python\"]", was ["mysql-connector-python"]
     # ./spec/umami/unit/recipes/_os_spec.rb:39:in `block (2 levels) in <top (required)>'

  10) blp-chef-workstation::_os installs package "ksh, lsof, procps, psmisc, strace, sysstat, tcpdump, telnet, unzip, zsh"
      Failure/Error: expect(chef_run).to install_package('ksh, lsof, procps, psmisc, strace, sysstat, tcpdump, telnet, unzip, zsh').with(package_name: '["ksh", "lsof", "procps", "psmisc", "strace", "sysstat", "tcpdump", "telnet", "unzip", "zsh"]')

        expected "yum_package[ksh, lsof, procps, psmisc, strace, sysstat, tcpdump, telnet, unzip, zsh]" to have parameters:

          package_name "[\"ksh\", \"lsof\", \"procps\", \"psmisc\", \"strace\", \"sysstat\", \"tcpdump\", \"telnet\", \"unzip\", \"zsh\"]", was ["ksh", "lsof", "procps", "psmisc", "strace", "sysstat", "tcpdump", "telnet", "unzip", "zsh”]

The likely behavior we want is that if we encounter an array (say, of packages), we write a looping test, like so:

%w(httpd ntpd).each do |pkg|
  describe package(pkg) do
    it { should be_installed }
  end
end
jjustice6 commented 7 years ago

Note also that https://github.com/chefspec/chefspec/issues/639 affects packages in particular.

You'll likely want the loop for the integration tests, but the array for unit tests.