metadata-json-lint 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +24 -0
  5. data/.rubocop_todo.yml +18 -0
  6. data/.travis.yml +24 -0
  7. data/Gemfile +3 -0
  8. data/LICENSE +13 -0
  9. data/README.md +63 -0
  10. data/Rakefile +15 -0
  11. data/lib/metadata-json-lint/version_requirement.rb +35 -0
  12. data/metadata-json-lint.gemspec +25 -0
  13. data/spec/spec_helper.rb +36 -0
  14. data/spec/version_requirement_spec.rb +28 -0
  15. data/tests/bad_license/Rakefile +2 -0
  16. data/tests/bad_license/expected +1 -0
  17. data/tests/bad_license/metadata.json +83 -0
  18. data/tests/broken/Rakefile +2 -0
  19. data/tests/broken/expected +1 -0
  20. data/tests/broken/metadata.json +87 -0
  21. data/tests/duplicate-dep/Rakefile +2 -0
  22. data/tests/duplicate-dep/expected +1 -0
  23. data/tests/duplicate-dep/metadata.json +91 -0
  24. data/tests/json_format/Rakefile +2 -0
  25. data/tests/json_format/expected +1 -0
  26. data/tests/json_format/metadata.json +83 -0
  27. data/tests/long_summary/Rakefile +2 -0
  28. data/tests/long_summary/expected +1 -0
  29. data/tests/long_summary/metadata.json +24 -0
  30. data/tests/missing_version_requirement/Rakefile +2 -0
  31. data/tests/missing_version_requirement/expected +1 -0
  32. data/tests/missing_version_requirement/metadata.json +27 -0
  33. data/tests/mixed_version_syntax/Rakefile +2 -0
  34. data/tests/mixed_version_syntax/expected +1 -0
  35. data/tests/mixed_version_syntax/metadata.json +30 -0
  36. data/tests/multiple_problems/Rakefile +2 -0
  37. data/tests/multiple_problems/expected +3 -0
  38. data/tests/multiple_problems/metadata.json +86 -0
  39. data/tests/no_dependencies/Rakefile +2 -0
  40. data/tests/no_dependencies/metadata.json +66 -0
  41. data/tests/no_files/.gitkeep +0 -0
  42. data/tests/no_files/expected +1 -0
  43. data/tests/no_pe/Rakefile +2 -0
  44. data/tests/no_pe/metadata.json +31 -0
  45. data/tests/no_version_range/Rakefile +2 -0
  46. data/tests/no_version_range/metadata.json +34 -0
  47. data/tests/noname/Rakefile +2 -0
  48. data/tests/noname/expected +1 -0
  49. data/tests/noname/metadata.json +86 -0
  50. data/tests/open_ended_dependency/Rakefile +2 -0
  51. data/tests/open_ended_dependency/expected +1 -0
  52. data/tests/open_ended_dependency/metadata.json +30 -0
  53. data/tests/perfect/Rakefile +2 -0
  54. data/tests/perfect/metadata.json +91 -0
  55. data/tests/proprietary/Rakefile +2 -0
  56. data/tests/proprietary/metadata.json +79 -0
  57. data/tests/rake_global_options/Rakefile +4 -0
  58. data/tests/rake_global_options/expected +1 -0
  59. data/tests/rake_global_options/metadata.json +79 -0
  60. data/tests/rake_multiple_json_options/Rakefile +14 -0
  61. data/tests/rake_multiple_json_options/metadata_license.json +79 -0
  62. data/tests/rake_multiple_json_options/metadata_ok.json +79 -0
  63. data/tests/tags_no_array/Rakefile +2 -0
  64. data/tests/tags_no_array/expected +1 -0
  65. data/tests/tags_no_array/metadata.json +96 -0
  66. data/tests/tags_with_array/Rakefile +2 -0
  67. data/tests/tags_with_array/metadata.json +92 -0
  68. data/tests/test.sh +157 -0
  69. data/tests/types/Rakefile +2 -0
  70. data/tests/types/expected +1 -0
  71. data/tests/types/metadata.json +88 -0
  72. metadata +131 -2
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__))
2
+ require 'metadata_json_lint'
3
+ MetadataJsonLint.options.fail_on_warnings = false
4
+
5
+ desc "Test metadata_lint on multiple files. Don't fail"
6
+ task :metadata_lint_multi do
7
+ MetadataJsonLint.parse('metadata_license.json') do |options|
8
+ options.strict_license = false
9
+ end
10
+ MetadataJsonLint.parse('metadata_ok.json') do |options|
11
+ options.strict_license = true
12
+ options.fail_on_warnings = true
13
+ end
14
+ end
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "puppetlabs-postgresql",
3
+ "version": "3.4.1",
4
+ "author": "Inkling/Puppet Labs",
5
+ "summary": "PostgreSQL defined resource types",
6
+ "license": "invalid_license",
7
+ "source": "git://github.com/puppetlabs/puppet-postgresql.git",
8
+ "project_page": "https://github.com/puppetlabs/puppet-postgresql",
9
+ "issues_url": "https://github.com/puppetlabs/puppet-postgresql/issues",
10
+ "operatingsystem_support": [
11
+ {
12
+ "operatingsystem": "RedHat",
13
+ "operatingsystemrelease": [
14
+ "5",
15
+ "6",
16
+ "7"
17
+ ]
18
+ },
19
+ {
20
+ "operatingsystem": "CentOS",
21
+ "operatingsystemrelease": [
22
+ "5",
23
+ "6",
24
+ "7"
25
+ ]
26
+ },
27
+ {
28
+ "operatingsystem": "OracleLinux",
29
+ "operatingsystemrelease": [
30
+ "5",
31
+ "6",
32
+ "7"
33
+ ]
34
+ },
35
+ {
36
+ "operatingsystem": "Scientific",
37
+ "operatingsystemrelease": [
38
+ "5",
39
+ "6",
40
+ "7"
41
+ ]
42
+ },
43
+ {
44
+ "operatingsystem": "Debian",
45
+ "operatingsystemrelease": [
46
+ "6",
47
+ "7"
48
+ ]
49
+ },
50
+ {
51
+ "operatingsystem": "Ubuntu",
52
+ "operatingsystemrelease": [
53
+ "10.04",
54
+ "12.04",
55
+ "14.04"
56
+ ]
57
+ }
58
+ ],
59
+ "requirements": [
60
+ {
61
+ "name": "puppet",
62
+ "version_requirement": "3.x"
63
+ }
64
+ ],
65
+ "dependencies": [
66
+ {
67
+ "name": "puppetlabs/stdlib",
68
+ "version_requirement": "4.x"
69
+ },
70
+ {
71
+ "name": "puppetlabs/apt",
72
+ "version_requirement": ">=1.1.0 <2.0.0"
73
+ },
74
+ {
75
+ "name": "puppetlabs/concat",
76
+ "version_requirement": ">= 1.1.0 <2.0.0"
77
+ }
78
+ ]
79
+ }
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "puppetlabs-postgresql",
3
+ "version": "3.4.1",
4
+ "author": "Inkling/Puppet Labs",
5
+ "summary": "PostgreSQL defined resource types",
6
+ "license": "Apache-2.0",
7
+ "source": "git://github.com/puppetlabs/puppet-postgresql.git",
8
+ "project_page": "https://github.com/puppetlabs/puppet-postgresql",
9
+ "issues_url": "https://github.com/puppetlabs/puppet-postgresql/issues",
10
+ "operatingsystem_support": [
11
+ {
12
+ "operatingsystem": "RedHat",
13
+ "operatingsystemrelease": [
14
+ "5",
15
+ "6",
16
+ "7"
17
+ ]
18
+ },
19
+ {
20
+ "operatingsystem": "CentOS",
21
+ "operatingsystemrelease": [
22
+ "5",
23
+ "6",
24
+ "7"
25
+ ]
26
+ },
27
+ {
28
+ "operatingsystem": "OracleLinux",
29
+ "operatingsystemrelease": [
30
+ "5",
31
+ "6",
32
+ "7"
33
+ ]
34
+ },
35
+ {
36
+ "operatingsystem": "Scientific",
37
+ "operatingsystemrelease": [
38
+ "5",
39
+ "6",
40
+ "7"
41
+ ]
42
+ },
43
+ {
44
+ "operatingsystem": "Debian",
45
+ "operatingsystemrelease": [
46
+ "6",
47
+ "7"
48
+ ]
49
+ },
50
+ {
51
+ "operatingsystem": "Ubuntu",
52
+ "operatingsystemrelease": [
53
+ "10.04",
54
+ "12.04",
55
+ "14.04"
56
+ ]
57
+ }
58
+ ],
59
+ "requirements": [
60
+ {
61
+ "name": "puppet",
62
+ "version_requirement": "3.x"
63
+ }
64
+ ],
65
+ "dependencies": [
66
+ {
67
+ "name": "puppetlabs/stdlib",
68
+ "version_requirement": "4.x"
69
+ },
70
+ {
71
+ "name": "puppetlabs/apt",
72
+ "version_requirement": ">=1.1.0 <2.0.0"
73
+ },
74
+ {
75
+ "name": "puppetlabs/concat",
76
+ "version_requirement": ">= 1.1.0 <2.0.0"
77
+ }
78
+ ]
79
+ }
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__))
2
+ require 'metadata-json-lint/rake_task'
@@ -0,0 +1 @@
1
+ Tags must be in an array. Currently it's a String.
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "puppetlabs-postgresql",
3
+ "version": "3.4.1",
4
+ "author": "Inkling/Puppet Labs",
5
+ "summary": "PostgreSQL defined resource types",
6
+ "license": "Apache-2.0",
7
+ "source": "git://github.com/puppetlabs/puppet-postgresql.git",
8
+ "project_page": "https://github.com/puppetlabs/puppet-postgresql",
9
+ "issues_url": "https://github.com/puppetlabs/puppet-postgresql/issues",
10
+ "tags": "postgres",
11
+ "operatingsystem_support": [
12
+ {
13
+ "operatingsystem": "RedHat",
14
+ "operatingsystemrelease": [
15
+ "5",
16
+ "6",
17
+ "7"
18
+ ]
19
+ },
20
+ {
21
+ "operatingsystem": "CentOS",
22
+ "operatingsystemrelease": [
23
+ "5",
24
+ "6",
25
+ "7"
26
+ ]
27
+ },
28
+ {
29
+ "operatingsystem": "OracleLinux",
30
+ "operatingsystemrelease": [
31
+ "5",
32
+ "6",
33
+ "7"
34
+ ]
35
+ },
36
+ {
37
+ "operatingsystem": "Scientific",
38
+ "operatingsystemrelease": [
39
+ "5",
40
+ "6",
41
+ "7"
42
+ ]
43
+ },
44
+ {
45
+ "operatingsystem": "Debian",
46
+ "operatingsystemrelease": [
47
+ "6",
48
+ "7"
49
+ ]
50
+ },
51
+ {
52
+ "operatingsystem": "Ubuntu",
53
+ "operatingsystemrelease": [
54
+ "10.04",
55
+ "12.04",
56
+ "14.04"
57
+ ]
58
+ }
59
+ ],
60
+ "requirements": [
61
+ {
62
+ "name": "pe",
63
+ "version_requirement": ">= 3.2.0 < 3.4.0"
64
+ },
65
+ {
66
+ "name": "puppet",
67
+ "version_requirement": "3.x"
68
+ }
69
+ ],
70
+ "dependencies": [
71
+ {
72
+ "name": "puppetlabs/stdlib",
73
+ "version_requirement": "1.2.3"
74
+ },
75
+ {
76
+ "name": "puppetlabs/apt",
77
+ "version_requirement": "< 1.2.3"
78
+ },
79
+ {
80
+ "name": "puppetlabs/puppetdb",
81
+ "version_requirement": "<= 1.2.3"
82
+ },
83
+ {
84
+ "name": "puppetlabs/vcsrepo",
85
+ "version_requirement": ">= 1.0.0 < 2.0.0"
86
+ },
87
+ {
88
+ "name": "puppetlabs/rabbitmq",
89
+ "version_requirement": "1.x"
90
+ },
91
+ {
92
+ "name": "puppetlabs/motd",
93
+ "version_requirement": "1.2.x"
94
+ }
95
+ ]
96
+ }
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__))
2
+ require 'metadata-json-lint/rake_task'
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "puppetlabs-postgresql",
3
+ "version": "3.4.1",
4
+ "author": "Inkling/Puppet Labs",
5
+ "summary": "PostgreSQL defined resource types",
6
+ "license": "Apache-2.0",
7
+ "source": "git://github.com/puppetlabs/puppet-postgresql.git",
8
+ "project_page": "https://github.com/puppetlabs/puppet-postgresql",
9
+ "issues_url": "https://github.com/puppetlabs/puppet-postgresql/issues",
10
+ "tags": ["postgres"],
11
+ "operatingsystem_support": [
12
+ {
13
+ "operatingsystem": "RedHat",
14
+ "operatingsystemrelease": [
15
+ "5",
16
+ "6",
17
+ "7"
18
+ ]
19
+ },
20
+ {
21
+ "operatingsystem": "CentOS",
22
+ "operatingsystemrelease": [
23
+ "5",
24
+ "6",
25
+ "7"
26
+ ]
27
+ },
28
+ {
29
+ "operatingsystem": "OracleLinux",
30
+ "operatingsystemrelease": [
31
+ "5",
32
+ "6",
33
+ "7"
34
+ ]
35
+ },
36
+ {
37
+ "operatingsystem": "Scientific",
38
+ "operatingsystemrelease": [
39
+ "5",
40
+ "6",
41
+ "7"
42
+ ]
43
+ },
44
+ {
45
+ "operatingsystem": "Debian",
46
+ "operatingsystemrelease": [
47
+ "6",
48
+ "7"
49
+ ]
50
+ },
51
+ {
52
+ "operatingsystem": "Ubuntu",
53
+ "operatingsystemrelease": [
54
+ "10.04",
55
+ "12.04",
56
+ "14.04"
57
+ ]
58
+ }
59
+ ],
60
+ "requirements": [
61
+ {
62
+ "name": "puppet",
63
+ "version_requirement": "3.x"
64
+ }
65
+ ],
66
+ "dependencies": [
67
+ {
68
+ "name": "puppetlabs/stdlib",
69
+ "version_requirement": "1.2.3"
70
+ },
71
+ {
72
+ "name": "puppetlabs/apt",
73
+ "version_requirement": "< 1.2.3"
74
+ },
75
+ {
76
+ "name": "puppetlabs/puppetdb",
77
+ "version_requirement": "<= 1.2.3"
78
+ },
79
+ {
80
+ "name": "puppetlabs/vcsrepo",
81
+ "version_requirement": ">= 1.0.0 < 2.0.0"
82
+ },
83
+ {
84
+ "name": "puppetlabs/rabbitmq",
85
+ "version_requirement": "1.x"
86
+ },
87
+ {
88
+ "name": "puppetlabs/motd",
89
+ "version_requirement": "1.2.x"
90
+ }
91
+ ]
92
+ }
@@ -0,0 +1,157 @@
1
+ #!/bin/bash
2
+ set -u
3
+
4
+ # Ensure this can be called from outside its directory.
5
+ cd $(dirname $0)
6
+
7
+ SUCCESS=0
8
+ FAILURE=1
9
+ STATUS=0
10
+
11
+ fail() {
12
+ echo $*
13
+ STATUS=1
14
+ }
15
+
16
+ # Tests the metadata-json-lint bin and if no additional arguments are given, also the rake task.
17
+ test() {
18
+ local name=$1; shift
19
+ local expect=$1; shift
20
+
21
+ test_bin $name $expect $*
22
+ # Only check the Rakefile when no additional arguments were passed to metadata-json-lint.
23
+ # In these cases, rake will likely have the opposite return code and cause false failures.
24
+ if [ $# -eq 0 ]; then
25
+ test_rake $name $expect metadata_lint
26
+ fi
27
+ }
28
+
29
+ test_bin() {
30
+ local name=$1; shift
31
+ local expect=$1; shift
32
+ local RESULT=-1
33
+ cd $name;
34
+ bundle exec metadata-json-lint $* metadata.json >last_output 2>&1
35
+ RESULT=$?
36
+ if [ $RESULT -ne $expect ]; then
37
+ fail "Failing Test '${name}' (unexpected exit code '${RESULT}' instead of '${expect}') (bin)"
38
+ echo " Note: you can examine '${name}/last_output' for any output"
39
+ else
40
+ # If the test is not expected to succeed then it should match an expected output
41
+ if [ $expect -eq $SUCCESS ]; then
42
+ echo "Successful Test '${name}' (bin)"
43
+ else
44
+ if [ -f expected ]; then
45
+ if grep --quiet -f expected last_output; then
46
+ echo "Successful Test '${name}' (bin)"
47
+ else
48
+ fail "Failing Test '${name}' (did not get expected output) (bin)"
49
+ echo " Comparing '${name}/expected' with '${name}/last_output':"
50
+ echo " Expected: '`cat expected`'"
51
+ echo " Actual: '`cat last_output`'"
52
+ fi
53
+ else
54
+ fail "Failing Test '${name}' (expected output file ${name}/expected is missing) (bin)"
55
+ echo " Actual output that needs tested ('${name}/last_output'): '`cat last_output`'"
56
+ fi
57
+ fi
58
+ fi
59
+ cd ..
60
+ }
61
+
62
+ test_rake() {
63
+ local name=$1; shift
64
+ local expect=$1; shift
65
+ local rake_task="${1-metadata_lint}"
66
+ local RESULT=-1;
67
+
68
+ cd $name;
69
+ bundle exec rake $rake_task >/dev/null 2>&1
70
+ RESULT=$?
71
+ if [ $RESULT -ne $expect ]; then
72
+ fail "Failing Test '${name}' (rake: ${rake_task})"
73
+ else
74
+ echo "Successful Test '${name}' (rake: ${rake_task})"
75
+ fi;
76
+ cd ..
77
+ }
78
+
79
+ # Run a broken one, expect FAILURE
80
+ test "broken" $FAILURE
81
+
82
+ # Run a perfect one, expect SUCCESS
83
+ test "perfect" $SUCCESS
84
+
85
+ # Run a broken one, expect FAILURE
86
+ test "noname" $FAILURE
87
+
88
+ # Run a broken one, expect FAILURE
89
+ test "types" $FAILURE
90
+
91
+ # Run a broken one, expect FAILURE
92
+ test "multiple_problems" $FAILURE
93
+
94
+ # Run a broken one, expect FAILURE
95
+ test "duplicate-dep" $FAILURE
96
+ # Run with --no-fail-on-warnings, expect SUCCESS
97
+ test "duplicate-dep" $SUCCESS --no-fail-on-warnings
98
+
99
+ # Run a broken one, expect FAILURE
100
+ test "bad_license" $FAILURE
101
+ # Run with --no-strict-license, expect SUCCESS
102
+ test "bad_license" $SUCCESS --no-strict-license --no-fail-on-warnings
103
+
104
+ # Run a broken one, expect FAILURE
105
+ test "long_summary" $FAILURE
106
+
107
+ # Run a broken one, expect FAILURE
108
+ test "mixed_version_syntax" $FAILURE
109
+
110
+ # Run one with empty dependencies array, expect SUCCESS
111
+ test "no_dependencies" $SUCCESS
112
+
113
+ # Run one with open ended dependency, expect SUCCESS
114
+ test "open_ended_dependency" $SUCCESS --no-fail-on-warnings
115
+ # Run one with open ended dependency and --strict-dependencies, expect FAILURE
116
+ test "open_ended_dependency" $FAILURE --strict-dependencies
117
+
118
+ # Run one with missing version_requirement and --no-strict-dependency, expect SUCCESS
119
+ test "missing_version_requirement" $SUCCESS --no-fail-on-warnings
120
+ # Run one with open ended dependency and --strict-dependencies, expect FAILURE
121
+ test "missing_version_requirement" $FAILURE --strict-dependencies
122
+
123
+ # Run test for "proprietary"-licensed modules, expect SUCCESS
124
+ test "proprietary" $SUCCESS
125
+
126
+ # Run without a metadata.json or Rakefile, expect FAILURE
127
+ test "no_files" $FAILURE
128
+
129
+ # Run with tags in an array in metadata.json, expect SUCCESS
130
+ test "tags_with_array" $SUCCESS
131
+
132
+ # Run with tags not in an array in metadata.json, expect FAILURE
133
+ test "tags_no_array" $FAILURE
134
+
135
+ # Run with json output format
136
+ test "json_format" $FAILURE --format json
137
+
138
+ # Test running without specifying file to parse
139
+ cd perfect
140
+ bundle exec metadata-json-lint
141
+ if [ $? -ne 0 ]; then
142
+ fail "Failing Test 'running without specifying metadata.json' (bin)"
143
+ else
144
+ echo "Successful Test 'running without specifying metadata.json' (bin)"
145
+ fi
146
+ cd ..
147
+
148
+ # Test changing the rake task using settings
149
+ # The bin test will fail due to strict licensing
150
+ # The rake test should pass due to licensing option being set in Rakefile
151
+ test_bin "rake_global_options" $FAILURE
152
+ test_rake "rake_global_options" $SUCCESS
153
+
154
+ # Test multiple lints with different options
155
+ test_rake "rake_multiple_json_options" $SUCCESS metadata_lint_multi
156
+
157
+ exit $STATUS