Skip to content

Commit

Permalink
Merge pull request #57 from james-stocks/update_tests
Browse files Browse the repository at this point in the history
Update tests to expect specific output
  • Loading branch information
rnelson0 authored Mar 13, 2017
2 parents f544815 + 8fd8198 commit 999c24e
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
Gemfile.lock
/.bundle
/vendor
tests/*/last_output
6 changes: 5 additions & 1 deletion lib/metadata_json_lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ def parse(metadata)
options = options().clone
# Configuration from rake tasks
yield options if block_given?
f = File.read(metadata)
begin
f = File.read(metadata)
rescue Exception => e
abort("Error: Unable to read metadata file: #{e.exception}")
end

begin
parsed = JSON.parse(f)
Expand Down
1 change: 1 addition & 0 deletions tests/bad_license/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Warning: License identifier Unknown-1.0 is not in the SPDX list: http://spdx.org/licenses/
1 change: 1 addition & 0 deletions tests/broken/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error: Unable to parse metadata.json: 743: unexpected token at
1 change: 1 addition & 0 deletions tests/duplicate-dep/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error: duplicate dependencies on puppetlabs/stdlib
1 change: 1 addition & 0 deletions tests/long_summary/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error: summary exceeds 144 characters in metadata.json
8 changes: 4 additions & 4 deletions tests/long_summary/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "foo-bar",
"version": "1.0.0",
"author": "foo/bar",
"summary": "This is obviously a way way tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long"
"summary": "This is obviously a way way tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long",
"license": "Apache-2.0",
"source": ""
"project_page": ""
"issues_url": ""
"source": "",
"project_page": "",
"issues_url": "",
"operatingsystem_support": [
{
"operatingsystem": "RedHat",
Expand Down
1 change: 1 addition & 0 deletions tests/missing_version_requirement/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Warning: Dependency puppetlabs/stdlib has an open ended dependency version requirement
1 change: 1 addition & 0 deletions tests/mixed_version_syntax/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Invalid 'version_requirement' field in metadata.json: Unparsable version range: ">= 3.2.x"
3 changes: 3 additions & 0 deletions tests/multiple_problems/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Error: Required field 'license' not found in metadata.json.
Error: Required field 'summary' not found in metadata.json.
Error: Deprecated field 'types' found in metadata.json.
1 change: 1 addition & 0 deletions tests/no_files/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error: Unable to read metadata file: No such file or directory
1 change: 1 addition & 0 deletions tests/noname/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error: Required field 'name' not found in metadata.json.
1 change: 1 addition & 0 deletions tests/open_ended_dependency/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Warning: Dependency puppetlabs/stdlib has an open ended dependency version requirement >= 3.2.0
1 change: 1 addition & 0 deletions tests/rake_global_options/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Warning: License identifier invalid_license is not in the SPDX list: http://spdx.org/licenses/
1 change: 1 addition & 0 deletions tests/tags_no_array/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Warning: Tags must be in an array. Currently it's a String.
26 changes: 23 additions & 3 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,30 @@ test_bin() {
local expect=$1; shift
local RESULT=-1
cd $name;
bundle exec metadata-json-lint $* metadata.json >/dev/null 2>&1
bundle exec metadata-json-lint $* metadata.json >last_output 2>&1
RESULT=$?
if [ $RESULT -ne $expect ]; then
fail "Failing Test '${name}' (bin)"
fail "Failing Test '${name}' (unexpected exit code '${RESULT}' instead of '${expect}') (bin)"
echo " Note: you can examine '${name}/last_output' for any output"
else
echo "Successful Test '${name}' (bin)"
# If the test is not expected to succeed then it should match an expected output
if [ $expect -eq $SUCCESS ]; then
echo "Successful Test '${name}' (bin)"
else
if [ -f expected ]; then
if grep --quiet "`cat expected`" last_output; then
echo "Successful Test '${name}' (bin)"
else
fail "Failing Test '${name}' (did not get expected output) (bin)"
echo " Comparing '${name}/expected' with '${name}/last_output':"
echo " Expected: '`cat expected`'"
echo " Actual: '`cat last_output`'"
fi
else
fail "Failing Test '${name}' (expected output file ${name}/expected is missing) (bin)"
echo " Actual output that needs tested ('${name}/last_output'): '`cat last_output`'"
fi
fi
fi
cd ..
}
Expand Down Expand Up @@ -125,6 +143,8 @@ fi
cd ..

# Test changing the rake task using settings
# The bin test will fail due to strict licensing
# The rake test should pass due to licensing option being set in Rakefile
test_bin "rake_global_options" $FAILURE
test_rake "rake_global_options" $SUCCESS

Expand Down
1 change: 1 addition & 0 deletions tests/types/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error: Deprecated field 'types' found in metadata.json.

0 comments on commit 999c24e

Please sign in to comment.