Skip to content

Commit

Permalink
Merge pull request #45 from petems/add_tag_check
Browse files Browse the repository at this point in the history
Adds feature to check tags
  • Loading branch information
rnelson0 authored Dec 6, 2016
2 parents 3b63cb0 + aa158bc commit a16d9b9
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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}")
Expand Down
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",
"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
Expand Up @@ -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
Expand Down

0 comments on commit a16d9b9

Please sign in to comment.