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

Misleading diagnostic from unit tests when an attribute expected to be an array is missing #940

Open
jcbollinger opened this issue Feb 2, 2021 · 7 comments
Labels
bug needs-triage Newly created issue that has not been reviewed by a PDK contributor

Comments

@jcbollinger
Copy link

Describe the bug
When a spec test asserts that a class or resource is declared with an attribute having an array value, but instead that class or resource is declared without specifying any value for that attribute, the resulting diagnostic from pdk test unit is misleading. For example:

  1) example on redhat-8-x86_64 is expected to contain Class[example] with arr => []
     Failure/Error:
       is_expected.to contain_class('example')
         .with(arr: [])
     
       expected that the catalogue would contain Class[example] with arr set to [] but it is set to [nil]
     # ./spec/classes/example_spec.rb:12:in `block (4 levels) in <top (required)>'

Specifically, the diagnostic says that the attribute is set to '[nil]', which appears to correspond to an array with an element having an undef value, as opposed to no value at all or undef.

In contrast, if the test instead asserts that the attribute has a scalar value then the resulting diagnostic reports that "it is set to nil". To the extent that the attribute can be considered to have any value when none has been declared, surely that value does not depend on the one that was asserted.

To Reproduce

The overall module structure was generated with pdk new module example.

Any class will do. The diagnostic quoted above was generated with this one:

class example { }

The above diagnostic was generated with this spec test:

# frozen_string_literal: true

require 'spec_helper'

describe 'example' do
  on_supported_os.each do |os, os_facts|
    context "on #{os}" do
      let(:facts) { os_facts }

      it do
        is_expected.to compile
        is_expected.to contain_class('example')
          .with(arr: [])
      end
    end
  end
end

The diagnostic generated does not seem to depend on whether the class or resource in question actually has an attribute of the specified name. All that matters is that

  1. an attribute is expected to have an array value, but instead is not declared at all or is explicitly declared undef; and
  2. if the class or resource type actually does have an attribute of the given name, then its type must permit the value to go unspecified and / or be explicitly undef, else a different diagnostic is generated.

Expected behavior
If a test asserts a value for a class or resource attribute, but no value is in fact expressly declared, then the diagnostic output should say "but it is set to nil", regardless of the data type of the asserted value.

Additional context

  • PDK installed via yum, from the repo yum.puppetlabs.com/puppet6/el/7/x86_64
  • PDK version 1.17.0
  • RedHat Enterprise Linux 7 / x86_64
@jcbollinger jcbollinger added bug needs-triage Newly created issue that has not been reviewed by a PDK contributor labels Feb 2, 2021
@github-actions
Copy link

This issue has been marked stale because it is open with no recent activity. The PDK Team is actively prioritizing existing bugs and new features, if this issue is still important to you please comment and we will add this to our backlog to complete.

@jcbollinger
Copy link
Author

Pursuant to the no-issue-activity label: I would rate this a low-priority issue, but I do account it a bug, and the fact that there has been no activity on it does not mean that it should not be fixed.

@github-actions
Copy link

This issue has been marked stale because it is open with no recent activity. The PDK Team is actively prioritizing existing bugs and new features, if this issue is still important to you please comment and we will add this to our backlog to complete.

@jcbollinger
Copy link
Author

Again, I acknowledge that this is probably a low-priority issue, but it still should be fixed.

@github-actions
Copy link

This issue has been marked stale because it is open with no recent activity. The PDK Team is actively prioritizing existing bugs and new features, if this issue is still important to you please comment and we will add this to our backlog to complete.

@jcbollinger
Copy link
Author

I would still like this issue to be fixed.

@david22swan
Copy link
Member

@jcbollinger I'm not sure if this is the right place to raise this error, this seems to be an issue with the rspec, not PDK itself?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs-triage Newly created issue that has not been reviewed by a PDK contributor
Projects
None yet
Development

No branches or pull requests

3 participants