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

Adds feature to check tags #45

Merged
merged 1 commit into from
Dec 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -19,3 +19,6 @@ Metrics/MethodLength:

Metrics/PerceivedComplexity:
Enabled: false

Metrics/ModuleLength:
Max: 120
5 changes: 5 additions & 0 deletions lib/metadata_json_lint.rb
Original file line number Diff line number Diff line change
@@ -95,6 +95,11 @@ def parse(metadata)
error_state = true if options[:strict_license]
end

if !parsed['tags'].nil? && !parsed['tags'].is_a?(Array)
puts "Warning: Tags must be in an array. Currently it's a #{parsed['tags'].class}."
error_state = true
end

return unless error_state
if options[:fail_on_warnings] == true
abort("Errors found in #{metadata}")
2 changes: 2 additions & 0 deletions tests/tags_no_array/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__))
require 'metadata-json-lint/rake_task'
96 changes: 96 additions & 0 deletions tests/tags_no_array/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"name": "puppetlabs-postgresql",
"version": "3.4.1",
"author": "Inkling/Puppet Labs",
"summary": "PostgreSQL defined resource types",
"license": "Apache-2.0",
"source": "git://github.com/puppetlabs/puppet-postgresql.git",
"project_page": "https://github.com/puppetlabs/puppet-postgresql",
"issues_url": "https://github.com/puppetlabs/puppet-postgresql/issues",
"tags": "postgres",
Copy link
Member

Choose a reason for hiding this comment

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

I think there should be a corresponding test where it is in an array. There appear to be no other metadata.json files used for testing with the tags value, so it's not being tested elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems sensible, will do!

Copy link
Member Author

Choose a reason for hiding this comment

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

Happy path test added! 👍

"operatingsystem_support": [
{
"operatingsystem": "RedHat",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "CentOS",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "OracleLinux",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "Scientific",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "Debian",
"operatingsystemrelease": [
"6",
"7"
]
},
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": [
"10.04",
"12.04",
"14.04"
]
}
],
"requirements": [
{
"name": "pe",
"version_requirement": ">= 3.2.0 < 3.4.0"
},
{
"name": "puppet",
"version_requirement": "3.x"
}
],
"dependencies": [
{
"name": "puppetlabs/stdlib",
"version_requirement": "1.2.3"
},
{
"name": "puppetlabs/apt",
"version_requirement": "< 1.2.3"
},
{
"name": "puppetlabs/puppetdb",
"version_requirement": "<= 1.2.3"
},
{
"name": "puppetlabs/vcsrepo",
"version_requirement": ">= 1.0.0 < 2.0.0"
},
{
"name": "puppetlabs/rabbitmq",
"version_requirement": "1.x"
},
{
"name": "puppetlabs/motd",
"version_requirement": "1.2.x"
}
]
}
2 changes: 2 additions & 0 deletions tests/tags_with_array/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__))
require 'metadata-json-lint/rake_task'
96 changes: 96 additions & 0 deletions tests/tags_with_array/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"name": "puppetlabs-postgresql",
"version": "3.4.1",
"author": "Inkling/Puppet Labs",
"summary": "PostgreSQL defined resource types",
"license": "Apache-2.0",
"source": "git://github.com/puppetlabs/puppet-postgresql.git",
"project_page": "https://github.com/puppetlabs/puppet-postgresql",
"issues_url": "https://github.com/puppetlabs/puppet-postgresql/issues",
"tags": ["postgres"],
"operatingsystem_support": [
{
"operatingsystem": "RedHat",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "CentOS",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "OracleLinux",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "Scientific",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "Debian",
"operatingsystemrelease": [
"6",
"7"
]
},
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": [
"10.04",
"12.04",
"14.04"
]
}
],
"requirements": [
{
"name": "pe",
"version_requirement": ">= 3.2.0 < 3.4.0"
},
{
"name": "puppet",
"version_requirement": "3.x"
}
],
"dependencies": [
{
"name": "puppetlabs/stdlib",
"version_requirement": "1.2.3"
},
{
"name": "puppetlabs/apt",
"version_requirement": "< 1.2.3"
},
{
"name": "puppetlabs/puppetdb",
"version_requirement": "<= 1.2.3"
},
{
"name": "puppetlabs/vcsrepo",
"version_requirement": ">= 1.0.0 < 2.0.0"
},
{
"name": "puppetlabs/rabbitmq",
"version_requirement": "1.x"
},
{
"name": "puppetlabs/motd",
"version_requirement": "1.2.x"
}
]
}
6 changes: 6 additions & 0 deletions tests/test.sh
Original file line number Diff line number Diff line change
@@ -89,6 +89,12 @@ test "proprietary" $SUCCESS
# Run without a metadata.json or Rakefile, expect FAILURE
test "no_files" $FAILURE

# Run with tags in an array in metadata.json, expect SUCCESS
test "tags_with_array" $SUCCESS

# Run with tags not in an array in metadata.json, expect FAILURE
test "tags_no_array" $FAILURE

# Test running without specifying file to parse
cd perfect
bundle exec metadata-json-lint