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

Deprecate and warn when comparing against OS name with capitals/spaces #2397

Merged
merged 4 commits into from
Jan 4, 2018

Conversation

jquick
Copy link
Contributor

@jquick jquick commented Dec 14, 2017

This change supports the new train lowercase/underscored platform names. inspec/train#228

Fixes #2407

This change will auto convert any profiles using the wrong format and give a warning to fix by 2.0.

Signed-off-by: Jared Quick jquick@chef.io

@jquick jquick requested a review from a team as a code owner December 14, 2017 18:10
@jquick jquick force-pushed the jq/platform_downcase_name branch 4 times, most recently from 80d8a54 to d4ab29d Compare December 18, 2017 18:47
@jquick jquick self-assigned this Dec 20, 2017
@jquick jquick changed the title DO NOT MERGE - Testing breaking Train name change Deprecate invalid platform name tests Dec 20, 2017
@jquick
Copy link
Contributor Author

jquick commented Dec 20, 2017

@adamleff - I think this is ready for review, it will want to go in tandem with the train release. inspec/train#228

Note: I will redo this to be off the platform resource once that gets merged in.

Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a couple of unit tests for NameCleaned? I'm thinking something for when translation was necessary, and something for when it wasn't? Just some checks using the == method you define should be good.

cleaned = other.downcase.tr(' ', '_')
Inspec::Log.warn "[DEPRECATED] Platform names will become lowercase in InSpec 2.0. Please match on '#{cleaned}' instead of '#{other}'"
end
super(other)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to compare against cleaned if we had to translate, right?

def [](name)
# convert string to symbol
name = name.to_sym if name.is_a? String
return self.name if name == :name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity purposes, we should probably change the method parameter from name to key or something like that so we're not overloading the use of name here.

@@ -6,6 +6,24 @@
require 'inspec/resource'

describe 'Inspec::Resources::Os' do
it 'verify NamedCleaned with uppercase' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgive the pun, but can we Clean this up a bit?

let(:cleaner) { Inspec::Resources::OSResource::NameCleaned }

it 'does something' do
  cleaner.new('blah')
  # some test here
end

It feels repetitious to be defining cleaner in each test like that. If you don't want to use a let, we should at least consolidate two lines per test:

it 'does something' do
  name = Inspec::Resources::OSResource::NameCleaned.new('something')
  # the test
end

Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditionally approved pending a train release and a commit here that uses it.

@adamleff adamleff changed the title Deprecate invalid platform name tests Deprecate and warn when comparing against OS name with capitals/spaces Jan 2, 2018
@adamleff adamleff added the Type: Enhancement Improves an existing feature label Jan 2, 2018
Signed-off-by: Jared Quick <jquick@chef.io>
Signed-off-by: Jared Quick <jquick@chef.io>
Signed-off-by: Jared Quick <jquick@chef.io>
Signed-off-by: Jared Quick <jquick@chef.io>
@adamleff adamleff merged commit 839ab3e into master Jan 4, 2018
@adamleff adamleff deleted the jq/platform_downcase_name branch January 4, 2018 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improves an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Force lowercase/underscore platform names
2 participants