diff --git a/.gitignore b/.gitignore index b844b14..e09cea3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ Gemfile.lock +pkg +.bundle diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..aedc15b --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.5.3 diff --git a/README.md b/README.md index b9b2f6a..76dc34a 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,41 @@ runs faster. Reads the Puppetfile in the current directory and installs them under the `path` provided as an argument. +### r10k:validate[path] +The validate rake task will determine if the url is a valid url by connecting +to the repository and verififying it actually exists and can be accessed. +Additional if a branch, tag, or ref is specified in the Puppetfile the validate +task will also verify that that branch/tag/ref exists in the remote repository. + +If you have ever deployed r10k to production only to find out a tag or branch is +missing this validate task will catch that issue. + +A exit status of 0 is returned if there are no faults, while a 1 is returned if +any module has a bad status. + +Status emojis can be customized by setting the following environment variables. + +Example + + * `GOOD_EMOJI='👍'` + * `BAD_EMOJI='😨'` + + +``` +NAME | URL | REF | STATUS +---------|-----------------------------------------------|--------------------------------|------- +splunk | https://github.com/cudgel/splunk.git | prod | 👍 +r10k | https://github.com/acidprime/r10k | v3.1.1 | 👍 +gms | https://github.com/npwalker/abrader-gms | gitlab_disable_ssl_verify_s... | 👍 +rbac | https://github.com/puppetlabs/pltraining-rbac | 2f60e1789a721ce83f8df061e13... | 👍 +acl | https://github.com/dobbymoodge/puppet-acl.git | master | 👍 +deploy | https://github.com/cudgel/deploy.git | master | 👍 +dotfiles | https://github.com/cudgel/puppet-dotfiles.git | master | 👍 +gitlab | https://github.com/vshn/puppet-gitlab | 00397b86dfb3487d9df768cbd36... | 👍 + +👍👍 Puppetfile looks good.👍👍 +``` + #### Limitations * It works only with modules from the [Forge](https://forge.puppetlabs.com), and Git. diff --git a/Rakefile b/Rakefile index 19b5c5d..ccca1d2 100644 --- a/Rakefile +++ b/Rakefile @@ -3,8 +3,14 @@ require 'rake/clean' require 'rubygems' require 'bundler/gem_tasks' require 'fileutils' +require 'rspec/core' +require 'rspec/core/rake_task' CLEAN.include("pkg/", "tmp/") CLOBBER.include("Gemfile.lock") -task :default => [:clean, :build] +task :default => [:spec] + +RSpec::Core::RakeTask.new(:spec) do |spec| + spec.pattern = FileList['spec/**/*_spec.rb'] +end diff --git a/lib/ra10ke.rb b/lib/ra10ke.rb index 75fad96..19e6bae 100644 --- a/lib/ra10ke.rb +++ b/lib/ra10ke.rb @@ -5,15 +5,17 @@ require 'ra10ke/syntax' require 'ra10ke/dependencies' require 'ra10ke/install' +require 'ra10ke/validate' require 'git' require 'semverse' - +require 'r10k/puppetfile' module Ra10ke class RakeTask < ::Rake::TaskLib include Ra10ke::Solve include Ra10ke::Syntax include Ra10ke::Dependencies include Ra10ke::Install + include Ra10ke::Validate attr_accessor :basedir, :moduledir, :puppetfile_path, :puppetfile_name, :force, :purge @@ -32,6 +34,7 @@ def initialize(*args) define_task_syntax(*args) define_task_dependencies(*args) define_task_install(*args) + define_task_validate(*args) end end diff --git a/lib/ra10ke/dependencies.rb b/lib/ra10ke/dependencies.rb index 27c5737..4b4c6d4 100644 --- a/lib/ra10ke/dependencies.rb +++ b/lib/ra10ke/dependencies.rb @@ -69,4 +69,3 @@ def define_task_dependencies(*_args) end end - diff --git a/lib/ra10ke/monkey_patches.rb b/lib/ra10ke/monkey_patches.rb new file mode 100644 index 0000000..2fff6b1 --- /dev/null +++ b/lib/ra10ke/monkey_patches.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class String + # colorization + def colorize(color_code) + "\e[#{color_code}m#{self}\e[0m" + end + + def red + colorize(31) + end + + def green + colorize(32) + end + + def yellow + colorize(33) + end + + # removes specified markes from string. + # @return [String] - the string with markers removed + def strip_comment(markers = ['#', "\n"]) + re = Regexp.union(markers) + index = (self =~ re) + index.nil? ? rstrip : self[0, index].rstrip + end +end diff --git a/lib/ra10ke/puppetfile_parser.rb b/lib/ra10ke/puppetfile_parser.rb new file mode 100644 index 0000000..77532be --- /dev/null +++ b/lib/ra10ke/puppetfile_parser.rb @@ -0,0 +1,83 @@ +# it might be desirable to parse the Puppetfile as a string instead of evaling it. +# this module allows you to do just that. +require 'ra10ke/monkey_patches' + +module Ra10ke + module PuppetfileParser + + # @return [Array] - returns a array of hashes that contain modules with a git source + def git_modules(file = puppetfile) + modules(file).find_all do |mod| + mod[:args].key?(:git) + end + end + + # @param puppetfile [String] - the absolute path to the puppetfile + # @return [Array] - returns an array of module hashes that represent the puppetfile + # @example + # [{:namespace=>"puppetlabs", :name=>"stdlib", :args=>[]}, + # {:namespace=>"petems", :name=>"swap_file", :args=>["'4.0.0'"]}] + def modules(puppetfile) + @modules ||= begin + return [] unless File.exist?(puppetfile) + + all_lines = File.read(puppetfile).lines.map(&:strip_comment) + # remove comments from all the lines + lines_without_comments = all_lines.reject { |line| line.match(/#.*\n/) }.join("\n").delete("\n") + lines_without_comments.split('mod').map do |line| + next nil if line =~ /^forge/ + next nil if line.empty? + + parse_module_args(line) + end.compact.uniq + end + end + + # @param data [String] - the string to parse the puppetfile args out of + # @return [Array] - an array of arguments in hash form + # @example + # {:namespace=>"puppetlabs", :name=>"stdlib", :args=>[]} + # {:namespace=>"petems", :name=>"swap_file", :args=>["'4.0.0'"]} + def parse_module_args(data) + return {} if data.empty? + args = data.split(',').map(&:strip) + # we can't guarantee that there will be a namespace when git is used + # remove quotes and dash and slash + namespace, name = args.shift.gsub(/'|"/, '').split(%r{-|/}) + name ||= namespace + namespace = nil if namespace == name + { + namespace: namespace, + name: name, + args: process_args(args) + } + end + + # @return [Array] - returns an array of hashes with the args in key value pairs + # @param [Array] - the arguments processed from each entry in the puppetfile + # @example + # [{:args=>[], :name=>"razor", :namespace=>"puppetlabs"}, + # {:args=>[{:version=>"0.0.3"}], :name=>"ntp", :namespace=>"puppetlabs"}, + # {:args=>[], :name=>"inifile", :namespace=>"puppetlabs"}, + # {:args=> + # [{:git=>"https://github.com/nwops/reportslack.git"}, {:ref=>"1.0.20"}], + # :name=>"reportslack", + # :namespace=>"nwops"}, + # {:args=>{:git=>"git://github.com/puppetlabs/puppetlabs-apt.git"}, + # :name=>"apt", + # :namespace=>nil} + # ] + def process_args(args) + results = {} + args.each do |arg| + a = arg.gsub(/'|"/, '').split(/\A\:|\:\s|\=\>/).map(&:strip).reject(&:empty?) + if a.count < 2 + results[:version] = a.first + else + results[a.first.to_sym] = a.last + end + end + results + end + end +end diff --git a/lib/ra10ke/validate.rb b/lib/ra10ke/validate.rb new file mode 100644 index 0000000..927e505 --- /dev/null +++ b/lib/ra10ke/validate.rb @@ -0,0 +1,126 @@ +# frozen_string_literal: true + +require 'ra10ke/monkey_patches' +require 'tempfile' +require 'table_print' +require 'ra10ke/puppetfile_parser' +require 'English' + +module Ra10ke + module Validate + + GOOD_EMOJI = ENV['GOOD_EMOJI'] || '👍' + BAD_EMOJI = ENV['BAD_EMOJI'] || '😨' + + # Validate the git urls and refs + def define_task_validate(*args) + desc 'Validate the git urls and branches, refs, or tags' + task :validate do + gitvalididation = Ra10ke::Validate::Validation.new(get_puppetfile.puppetfile_path) + exit_code = 0 + if gitvalididation.bad_mods? + exit_code = 1 + message = BAD_EMOJI + ' Not all modules in the Puppetfile are valid. '.red + BAD_EMOJI + else + message = GOOD_EMOJI + ' Puppetfile looks good. '.green + GOOD_EMOJI + end + tp gitvalididation.sorted_mods, :name, { url: { width: 50 } }, :ref, :status + abort(message) if exit_code.positive? + puts message + end + end + + class Validation + include Ra10ke::PuppetfileParser + + attr_reader :puppetfile + + def initialize(file) + file ||= './Puppetfile' + @puppetfile = File.expand_path(file) + abort("Puppetfile does not exist at #{puppetfile}") unless File.readable?(puppetfile) + end + + # @return [Boolean] - return true if the ref is valid + # @param url [String] - the git string either https or ssh url + # @param ref [String] - the ref object, branch name, tag name, or commit sha, defaults to HEAD + def valid_ref?(url, ref = 'HEAD') + raise ArgumentError unless ref + found = all_refs(url).find do |sha, data | + # we don't need to bother with these types + next if data[:type] == :pull || data[:type] == :merge_request + # is the name equal to the tag or branch? Is the commit sha equal? + data[:name].eql?(ref) || sha.slice(0,8).eql?(ref.slice(0,8)) + end + !found.nil? + end + + # @return [Hash] - a hash of all the refs associated with the remote repository + # @param url [String] - the git string either https or ssh url + # @example + # {"0ec707e431367bbe2752966be8ab915b6f0da754"=>{:ref=>"refs/heads/74110ac", :type=>:branch, :subtype=>nil, :name=>"74110ac"}, + # "07bb5d2d94db222dca5860eb29c184e8970f36f4"=>{:ref=>"refs/pull/74/head", :type=>:pull, :subtype=>:head, :name=>"74"}, + # "156ca9a8ea69e056e86355b27d944e59d1b3a1e1"=>{:ref=>"refs/heads/master", :type=>:branch, :subtype=>nil, :name=>"master"}, + # "fcc0532bbc5a5b65f3941738339e9cc7e3d767ce"=>{:ref=>"refs/pull/249/head", :type=>:pull, :subtype=>:head, :name=>"249"}, + # "8d54891fa5df75890ee15d53080c2a81b4960f92"=>{:ref=>"refs/pull/267/head", :type=>:pull, :subtype=>:head, :name=>"267"} } + def all_refs(url) + data = `git ls-remote --symref #{url}` + raise "Error downloading #{url}" unless $CHILD_STATUS.success? + data.lines.reduce({}) do |refs, line| + sha, ref = line.split("\t") + next refs if sha.eql?('ref: refs/heads/master') + _, type, name, subtype = ref.chomp.split('/') + next refs unless name + type = :tag if type.eql?('tags') + type = type.to_sym + subtype = subtype.to_sym if subtype + type = :branch if type.eql?(:heads) + refs[sha] = {ref: ref.chomp, type: type, subtype: subtype, name: name } + refs + end + end + + # @return [Boolean] - return true if the commit sha is valid + # @param url [String] - the git string either https or ssh url + # @param ref [String] - the sha id + def valid_commit?(url, sha) + return false if sha.nil? || sha.empty? + return true if valid_ref?(url, sha) + Dir.mktmpdir do |dir| + `git clone --no-tags #{url} #{dir} 2>&1 > /dev/null` + Dir.chdir(dir) do + `git show #{sha} 2>&1 > /dev/null` + $CHILD_STATUS.success? + end + end + end + + # @return [Array[Hash]] array of module information and git status + def all_modules + begin + git_modules(puppetfile).map do |mod| + ref = mod[:args][:ref] || mod[:args][:tag] || mod[:args][:branch] + valid_ref = valid_ref?(mod[:args][:git], ref) || valid_commit?(mod[:args][:git], mod[:args][:ref]) + { + name: mod[:name], + url: mod[:args][:git], + ref: ref, + valid_ref?: valid_ref, + status: valid_ref ? Ra10ke::Validate::GOOD_EMOJI : Ra10ke::Validate::BAD_EMOJI + } + end + end + end + + # @return [Boolean] - true if there are any bad mods + def bad_mods? + all_modules.find_all { |mod| !mod[:valid_ref?] }.count > 0 + end + + # @return [Hash] - sorts the mods based on good/bad + def sorted_mods + all_modules.sort_by { |a| a[:valid_ref?] ? 1 : 0 } + end + end + end +end diff --git a/ra10ke.gemspec b/ra10ke.gemspec index 9b28117..0bbe4ec 100644 --- a/ra10ke.gemspec +++ b/ra10ke.gemspec @@ -22,4 +22,6 @@ Gem::Specification.new do |spec| spec.add_dependency "git" spec.add_dependency "solve" spec.add_dependency 'semverse', '~> 2.0' + spec.add_dependency 'table_print', '~> 1.5.6' + spec.add_development_dependency 'rspec', '~> 3.6' end diff --git a/spec/fixtures/Puppetfile b/spec/fixtures/Puppetfile new file mode 100644 index 0000000..be3659d --- /dev/null +++ b/spec/fixtures/Puppetfile @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +forge 'http://forge.puppetlabs.com' + +mod 'puppetlabs/inifile', '2.2.0' +mod 'puppetlabs/stdlib', '4.24.0' +mod 'puppetlabs/concat', '4.0.0' +mod 'puppetlabs/ntp', '6.4.1' + +# introduced for tomcat module collaboration with uws +mod 'puppet-archive', '3.1.1' + +mod 'gitlab', + git: 'https://github.com/vshn/puppet-gitlab', + ref: '00397b86dfb3487d9df768cbd3698d362132b5bf' # master + +mod 'r10k', + git: 'https://github.com/acidprime/r10k', + tag: 'v3.1.1' + +mod 'gms', + git: 'https://github.com/npwalker/abrader-gms', + branch: 'gitlab_disable_ssl_verify_support' + +mod 'pltraining-rbac', + git: 'https://github.com/puppetlabs/pltraining-rbac', + ref: '2f60e1789a721ce83f8df061e13f8bf81cd4e4ce' + +mod 'puppet-acl', + git: 'https://github.com/dobbymoodge/puppet-acl.git', + branch: 'master' + +mod 'deploy', + git: 'https://github.com/cudgel/deploy.git', + branch: 'master' + +mod 'dotfiles', + git: 'https://github.com/cudgel/puppet-dotfiles.git', + branch: 'master' + +mod 'splunk', + git: 'https://github.com/cudgel/splunk.git', + branch: 'prod' diff --git a/spec/fixtures/Puppetfile_test b/spec/fixtures/Puppetfile_test new file mode 100644 index 0000000..bb9faf0 --- /dev/null +++ b/spec/fixtures/Puppetfile_test @@ -0,0 +1,12 @@ +mod 'puppet-hiera', + git: 'https://github.com/voxpupuli/puppet-hiera.git', + tag: '6.0.0' + +mod 'puppet-hiera', + git: 'https://github.com/voxpupuli/puppet-hiera.git', + tag: 'v6.0.0' + +mod 'puppet-hiera', + git: 'https://github.com/voxpupuli/puppet-hiera.git', + tag: 'abc' + \ No newline at end of file diff --git a/spec/fixtures/Puppetfile_with_bad_refs b/spec/fixtures/Puppetfile_with_bad_refs new file mode 100644 index 0000000..cce2767 --- /dev/null +++ b/spec/fixtures/Puppetfile_with_bad_refs @@ -0,0 +1,10 @@ +forge "http://forge.puppetlabs.com" + +mod 'gitlab', + :git => 'https://github.com/vshn/puppet-gitlab', + :ref => '00397b86dfb3487d9df768cbd3698d362132b5bf' # master + +mod 'r10k', + :git => 'https://github.com/acidprime/r10k', + :tag => 'bad' + \ No newline at end of file diff --git a/spec/fixtures/reflist.txt b/spec/fixtures/reflist.txt new file mode 100644 index 0000000..295106a --- /dev/null +++ b/spec/fixtures/reflist.txt @@ -0,0 +1,290 @@ +ref: refs/heads/master HEAD +156ca9a8ea69e056e86355b27d944e59d1b3a1e1 HEAD +0ec707e431367bbe2752966be8ab915b6f0da754 refs/heads/74110ac +07bb5d2d94db222dca5860eb29c184e8970f36f4 refs/heads/fix_version +156ca9a8ea69e056e86355b27d944e59d1b3a1e1 refs/heads/master +fcc0532bbc5a5b65f3941738339e9cc7e3d767ce refs/heads/modulesync +8d54891fa5df75890ee15d53080c2a81b4960f92 refs/heads/rnelson0-patch-1 +1e73763bc2d9e6d0e3f9b1f212e7a73c2838bed0 refs/pull/1/head +b59c936b34086f719cb6d28a50e774ca22a77121 refs/pull/1/merge +6eca20525cd290315b28a45e898e37830622f833 refs/pull/10/head +8831444d775addccd106cdf00dc2ab0eec2f9d8b refs/pull/10/merge +595dd8b9916c6975f33c94f15f4a0508eed30896 refs/pull/100/head +34d91cb8a66f8f5d276e4fa16964611041a1583b refs/pull/101/head +62fee8e705e72addf21cf1bb42826ff092a00283 refs/pull/102/head +a241e425eff63cc0279c2812969850987d7ae30b refs/pull/103/head +275f742651ad86a6adc6839ef005507a2acbc310 refs/pull/104/head +fde0b2cc5ad230f7ab518a54eb6b1fb0e1c30db6 refs/pull/105/head +06b69092778dedd9359fc0a7d12c0958545e44de refs/pull/105/merge +631a70ed9efa9488bea9c64be432b072cad439f3 refs/pull/106/head +1081aabc1f7881d34656f4d5e3f5b7010f529548 refs/pull/106/merge +92f84f4fdd2ce37c836d8cae16faef4fcbe92092 refs/pull/107/head +15ccd22c3918ecb37bcd6fe37da3b3cc75f2e09a refs/pull/107/merge +c3b726a4a775f5a2568be31dd58c0e18aa935258 refs/pull/11/head +8519261ae226586a7f5181a09128e4dea8f70e58 refs/pull/110/head +9d63ac78bc3ca8a903ed738dbdf42ac2355c3dd0 refs/pull/111/head +d639c670b6fdf95156a8dab3fb5e670a26d66186 refs/pull/112/head +bb36404711d319e1d6de063137f291b4b658f601 refs/pull/116/head +204b7342b1ce18452f3d1cea233fa4e3ca543d21 refs/pull/117/head +aecf3d9a0fb1330edb554c5ad512ff37302d1da2 refs/pull/119/head +dcff0a785e6c7e9d44226af157bb14ed6f15002e refs/pull/12/head +48654ae43d5579ceaa22f52ff5d3fe4ca78e98ca refs/pull/120/head +2ca529e8df7d90a136a9cd719389108e62a610ce refs/pull/121/head +b31864fe957d1788b91c0584cbdb0289cde516e6 refs/pull/123/head +421eb7c09ebc630103c7d0c7ffe79130322d575a refs/pull/125/head +66405ef32bcded15603426144d37abbdc691040c refs/pull/127/head +2613298b7005bcd8acba2cd824b09d5773bc3eea refs/pull/13/head +6d6d2d3e5cf8b6ca275ec7eef19e3075196972a5 refs/pull/13/merge +56e5c2ceac87a6253def854d21575a7694ebfc10 refs/pull/130/head +8a05a98e98ec1aadb56dd6f4da8774db5098c9af refs/pull/131/head +767196650c9130b12e9bd80db24da89905a6ba5c refs/pull/133/head +faa08ba48e9e7d4419b6f36beb8e0c9da816faa5 refs/pull/133/merge +1f9024a864646f7073b16449ca3610ee81caf4a7 refs/pull/134/head +361a9e371f1b48c3916c08063b22c064cb9665c4 refs/pull/135/head +566270505c366364eec15213fad569e5a2322655 refs/pull/136/head +82a38191aa00f160f8ff3a8e16e8b09a1a483e15 refs/pull/137/head +b831b75466276a7718f21e88c28140a216102528 refs/pull/139/head +bb4ce9bef78e42985ad70c186bfb72cabb651491 refs/pull/14/head +c8630f80c50cbc9c2199f2b28e3cb8252c7a2bb2 refs/pull/142/head +ef2696a4c75a48fb3392a9a87fbb1a56d27a2ce5 refs/pull/143/head +6508822e9e065af86f8024de06ed5ed80f120668 refs/pull/144/head +8087a669da0a1ad292b466e5c4d3e136dcfb8706 refs/pull/145/head +2fc5ae2be90a22cc2f6014b5f07284279d594503 refs/pull/148/head +4474243b280c69bb57cea0c84c78bc6237fb9724 refs/pull/149/head +20270c4e83d53c6e75aef78bcf83f5621204d7c2 refs/pull/15/head +cfa7a7af2a9ea756390e2c81dc562b6a526da3bf refs/pull/15/merge +562ce55321bcf00f8cae58e66f744333e017f20d refs/pull/150/head +1c2cc834f586bb626ef018239db620e9e8d00773 refs/pull/151/head +37a704b0d863f8817e6dde362ca38fbb7029e439 refs/pull/154/head +e0d46996ec27d66a5a1e5759b5d92a9ba6a0bdf3 refs/pull/155/head +ec4f6b86d6be8bd845b8f5bf311ded575c2fb7f7 refs/pull/156/head +0ed3fab31ab4ecd466f49c01c97b9b57be5d032f refs/pull/157/head +962de53f6d086f364c892f34070badc380bb5b22 refs/pull/159/head +b8fa15bc37d400d30f436f6fddba67b1ea0cf60e refs/pull/16/head +379aba0478227014d1f367d53e0285522cccca30 refs/pull/160/head +ce7c1852246057faa737e9987c42ab227598868e refs/pull/162/head +3b89335832e0a3f9e6884f35a00a8d98eb38df0e refs/pull/163/head +0c5a6f601c84c3ef78d2563fe7738fbc5e81a9b9 refs/pull/164/head +80f28faaae551c1a01658d2a111ab225588a052e refs/pull/165/head +e4c1d30280a9398a04f4b0bcf69fe50e6721e15a refs/pull/166/head +bea56bf399262d72604d62ed8af8a5be0b731d15 refs/pull/167/head +dadcafc081d590d00ec47d87de9d3cf8cc21cdc3 refs/pull/168/head +36372ecee8c3c5d020cfb3914cdcbca3ea7626c3 refs/pull/169/head +7e1a2b4d3ae6963f6841b2bd51febbe02e521de5 refs/pull/170/head +b19e30857f2806bf41bd051bfbcb2d18ec3ae2da refs/pull/170/merge +5268a4aa1963981c55e00b944e71624c664f71b7 refs/pull/172/head +3dfaa03a50941ef72fc36fa7ec8cf72c20331bf3 refs/pull/173/head +3bae731eff94c91e6ad54714f637c0c3e803cb0c refs/pull/175/head +dce6a4f4f013e94b7ce6be66840a6edd7941b167 refs/pull/176/head +682c875165ba65fa69c592667075d1ddf4240ca4 refs/pull/178/head +76210d85889814721b879af8f094415b9d682e7d refs/pull/179/head +0f8d16c921e881f9d419259413645b004c9d605d refs/pull/18/head +81d63e664c7744e1f850ec9a88271a01d0f5bc1a refs/pull/180/head +50b840a0e76929fe243a2a36c14b0d796fe09c87 refs/pull/181/head +6c7550a8bc78ccae6b5127bce52837e86b94a870 refs/pull/181/merge +c474980937d7d016c4197826b9705a1218d3e920 refs/pull/182/head +a117f20d095c67837ba058c37204491416cc0b15 refs/pull/182/merge +83ffe686dd8d1752097ca02bc9c59a56279f0988 refs/pull/183/head +10dcb56ed1a230b087c99bfd0eebc9b01ffce383 refs/pull/184/head +3c577f947e6c5c4788b173637ee73b556bfbf43d refs/pull/185/head +53251c7cbfeefaff8bbb8a7b19530cf3021632a7 refs/pull/186/head +42c4450df35acb3be444acc900f18042fa2579f3 refs/pull/188/head +3edac6565d3bc3aa0bf1abc8f8b1ca5f72f28a89 refs/pull/190/head +a2ed086a929c0f0f483857824036000d6e03d7cd refs/pull/191/head +92bc9de3b9b002ded8c03618f9e0818d1cd8dd8e refs/pull/192/head +d2d81a1de6d5e76a7897bc466c1c9ccc98537fda refs/pull/192/merge +bd212d186b3f92e48f35f1c8ead280990c866238 refs/pull/193/head +cb653b0947361d368488438e9fd115e4155786a2 refs/pull/194/head +39e9e132f48025da15df62c0d73127625e43d52b refs/pull/195/head +a1f706289bc5fe8cb89f0696587e62ca10338695 refs/pull/196/head +cf5013d2399d88373ebc15c95e0c39da1e0e5be4 refs/pull/197/head +05e1b72fbfa6881f82ed49731b982984a47c8b0a refs/pull/198/head +76f3abbf2d45278752932834f45f02a1f7b6eb02 refs/pull/199/head +1103ed378e5af878ded8a3a53af4e891de182fb7 refs/pull/2/head +44284fd102116da664a076f92da7ff7f676ffbd1 refs/pull/2/merge +8165ba665c9916f0d52429db4a700a2649117dff refs/pull/200/head +d00fb7576610b1b9606af06c4b5f7739c543b665 refs/pull/203/head +8524690928993e1f9273420e087e75ba9c4c6692 refs/pull/204/head +4f4c90dc5046acd0278270d2915ef66f3b8be011 refs/pull/205/head +4dcdd547a15bc799545564860d9734a0ca1e6e77 refs/pull/207/head +2071c4fe63b09c4b33fa10b26ad6a81f4fd5ad4b refs/pull/208/head +8c217235edb80d27a999c95db5a7eb75fc39fd8d refs/pull/209/head +81c5d76d5f773393f487ee9eaa7a86fed745e226 refs/pull/210/head +308214bc3ea9967aeca63a1552bf34d3aa99a729 refs/pull/211/head +48dd6ab0dddd0dc4126e824dee275b08a12a5953 refs/pull/212/head +ae5e101c1d1c7dccfa18791c09d9fac77042ff04 refs/pull/213/head +1aa41f958fe4081056be7bb8b5abe07342878b4d refs/pull/216/head +62139b3b4918e65d92023e61ee9c195d08b2259b refs/pull/217/head +18da283d30a188fe387df7db9423489ec3035fb7 refs/pull/218/head +a9cd4935420b9ac332bd647608948cec33fd6777 refs/pull/219/head +46c9a5a74be98f66c43c21248d53f3d5aff97771 refs/pull/22/head +273ed93b0389c56c3fcff54f1a5cb7a55a5b499f refs/pull/221/head +9608d3af35a2585d62a3e6012e4fac98d13b6ce0 refs/pull/222/head +53aa8ec2876b788d89c6f46b86e4b18e0914a4fc refs/pull/223/head +92ab0e39f2fd17af0ca8695d4ca95e86e9b03d24 refs/pull/225/head +9f539064d7025aec0744665d96a7d9291ffe6838 refs/pull/226/head +9adaec0b0179ba9874195009a3fbf5ac6014fc39 refs/pull/226/merge +194d0b3d2cf2c9c67ccfe0c482981a8a2a9ce737 refs/pull/227/head +376a621d8da483ace131033691f4faf5f6d8c9d1 refs/pull/228/head +bd08b5047f0463e48ce1b93c787b07aa8bcc7b62 refs/pull/229/head +29c9a77239d16e0de34327446eab1a362760a5f2 refs/pull/229/merge +d7c2effaa3c4a74d088fb2196b6cdf2d71476d12 refs/pull/231/head +b8ef7b793c11ff6337b091f4ed8a1ab953a06ce1 refs/pull/232/head +ef02e7ab558212aa6750559288728e4918f6af54 refs/pull/233/head +bb4f7ca2ad8918b61f751281997b6b507a0ff002 refs/pull/234/head +bc3b1ccbb8908c1ea823aaf05da804ded072ad69 refs/pull/236/head +cf68109dca9a7c6a5c0d6ada6c1531b72a0b89e9 refs/pull/237/head +286b108c6cd5e76e294a1a5825f0862d34118e21 refs/pull/238/head +1520a7d3ef40b516b513dd1248648b1dce9eb32d refs/pull/239/head +40ac653d2c626a4ca8f4dfec9a1a9a559553fb7f refs/pull/24/head +fd0cc9c53d01a6d46b3e9b55231f25d010ccecc2 refs/pull/24/merge +18ccb629f973b505d4a18a4ea7de39fd4f4ec20e refs/pull/240/head +24f680b347035b07060bd4e31eb1c840d9de1053 refs/pull/241/head +ef4d553c7b3eeabbe265c30901d33ad5d9a2e5ff refs/pull/242/head +e486af38bba794522ec5675713a163bc426f71e3 refs/pull/244/head +4f12a988547520b3542ce44b8f32bee0b14df88b refs/pull/246/head +71ab0591ef3d54a5368ef50b60749676917d2c25 refs/pull/247/head +fcc0532bbc5a5b65f3941738339e9cc7e3d767ce refs/pull/249/head +3f8dd89efcce9154e5bc297749072cbce906c662 refs/pull/25/head +c704560397b04ba90ceee591e74660d8e689d5e2 refs/pull/250/head +b76695cee7ffd5d8ae0dd75f9e369aa56ae632bb refs/pull/251/head +ddde6afccbfcd4275522810421ceb5300f7a406b refs/pull/253/head +30a38db35fa93e6f76d99f5a2bcf0b5bac7317a0 refs/pull/254/head +88a0730df246e9258475b8c7120478ca4301fdd8 refs/pull/255/head +aba2ce8607690573ce48439a8fc8cad901aea732 refs/pull/256/head +447ff87b64460a6c02225f8ff5ba92d3f8dbae03 refs/pull/257/head +7d2cdca541069517f7969375ead3d2c444f9b42a refs/pull/258/head +221a199d113985e43cb30a8040d5c2ef38a9a704 refs/pull/259/head +0225a1ee8e55ed98202f5b6756b44b93b57fa761 refs/pull/260/head +0e5525ed8065b3ea418934cdc569b29007a5b772 refs/pull/261/head +2d01860aa51f3dcad1babcf86ae885ddaa9b9453 refs/pull/262/head +c89c34fa4878abbc8a298b769bc67918be561c94 refs/pull/264/head +2c42371cdf44753ffbc6931773de1f87c0753293 refs/pull/266/head +8d54891fa5df75890ee15d53080c2a81b4960f92 refs/pull/267/head +3f1855f71bdca4a205c3a8998e8e38038df4c422 refs/pull/267/merge +0522809e5e472419120aa449bd817678ec237366 refs/pull/268/head +808b7b71798275ee8e1b93929a74e16c451aba09 refs/pull/269/head +d15c194a874c437743295ce29ba0b2e4cf673f98 refs/pull/27/head +f706647fdfed5c4a39b4d3fb96b47d302669e380 refs/pull/270/head +dca994acbe017db9d408172e2b7f2aef20563a2f refs/pull/270/merge +6ef2f6193da1d6d79223e9d8c5071fb0007ec3de refs/pull/28/head +4da47a821041fa051f9e16cd49b7881cba131a6d refs/pull/29/head +c8b57cdadac36790d2070267ca845059268d6ea2 refs/pull/3/head +bf858e0fe3c54fca763e2bbb8fce334ff1f38ddd refs/pull/3/merge +73ef7b45a0b54ef6de6dc8a7b33f806da03a439c refs/pull/30/head +05f0b0461edbfe5831cb83f7657ed5c4d7c26e1d refs/pull/32/head +c4347a3e557f2ee42017b5ba0a2d8e77d4a14900 refs/pull/33/head +07c9875e5099436ab769487e8049d8d5669e8596 refs/pull/33/merge +9abc48d7f9b37e7667495197a9afda00de29369e refs/pull/34/head +a895ee7582d5bdf91b2482d784f2134d80c5dc8f refs/pull/35/head +03f3129cf834a46e2803b622d93becac2e61bde9 refs/pull/36/head +ca4eee0d7d6b1c3c2f55b08b3b6325020b8c8eb2 refs/pull/36/merge +d52758cbf2f4367d755f77610c2104f1871075f0 refs/pull/37/head +fda1f07fd8509eeb6c137dba19a0ec1338b2c0a9 refs/pull/39/head +11103dc9d078af9014fea4b9a7a9b765b67e1c0a refs/pull/4/head +1fd96cddb9576b9e64405cd6e3f09d0ae491356c refs/pull/4/merge +c37716566ff5da758fd91921aa9d170f50febbd7 refs/pull/40/head +072bd5a0bf356d52309a69256504939bf48d795a refs/pull/41/head +1e9e04972bdb9f82c3382fa7dcf00d21fe0ee262 refs/pull/42/head +2b70a577a3561265ea879a4e2af749398990d126 refs/pull/43/head +f4bafc5d7d46bfc0e570d288c169cef35288f90f refs/pull/43/merge +dcbcf61c17306dc524ab31295ceb51ca416afa31 refs/pull/44/head +89cd0c82d12a9b3c6d47d1ddbd08ce1c7c31ddd3 refs/pull/45/head +073be8433701af539c55b30fa2ce20ae6e11b381 refs/pull/45/merge +a6d172079a2d13cf0662255b4f03acd55b23f9bb refs/pull/49/head +6a76cb101e93a67c4dfeaf1f17050426109ddf42 refs/pull/5/head +d45aa7f303207d57cbae0169ff6b8f11ec1c514a refs/pull/5/merge +5014ac2aa5abf5c682cc665d627c8cd272ecceea refs/pull/50/head +d102413549955b1fda6b7d2a0845fd84c3ab369c refs/pull/51/head +975abc542e0beefaa3042d972064bfc4991385e4 refs/pull/52/head +7ca06a5365908775c97d3a64f968792d450451ee refs/pull/54/head +4565f6d8688d4256174ec8998b2164cf65c64227 refs/pull/54/merge +eb916f1c0f1b38942a9c3762ffb7185fad3ae991 refs/pull/56/head +d5ca70e045c648cb84c0b578882498cad3d267ea refs/pull/57/head +f15842a4aaca0d031fb50e6a615b408b7c9ed6ef refs/pull/58/head +96de773e865416d04a952b71dce40a0780a6d3a8 refs/pull/59/head +c57e4955680e91cc2e15c3e7f1a22650948c4da2 refs/pull/6/head +c507086ae7d47023ce12ac4a629537b898bb23e4 refs/pull/6/merge +52887ebcf62a976ebf92a26c07a7ab74ed108cb6 refs/pull/60/head +6c388b7d9e9d87a4dba7ad86b70cfa9001b92039 refs/pull/64/head +cea49d405eb95bbfc53756170183221967687f62 refs/pull/65/head +7d43ffe1c6de460dc163e6709c3b0a3025da2a1a refs/pull/66/head +7932c73155bc8b46af5eca69e118e2ca398a25d8 refs/pull/68/head +7c95ed6fafd1ecd82851b9fac46eda73e4b908a4 refs/pull/69/head +49054e6bb5dd376184a8f4a83c69b43b1fd19010 refs/pull/69/merge +d09814c47592f4bbd70216b24958ee4c4800852b refs/pull/7/head +a24799789b582966662cf04397846e15c6be6f8c refs/pull/7/merge +cbf079bf84f40827ed4b0ea228b179f0826ddf7e refs/pull/70/head +6915420803a6b26169b9a396aada9e2e6511cae6 refs/pull/71/head +a2398b8b6390867dde8ef61ba597b901ce67612c refs/pull/73/head +0141ae4460d7a71f51023bc13eed0a216268af3d refs/pull/73/merge +07bb5d2d94db222dca5860eb29c184e8970f36f4 refs/pull/74/head +9eb823772f343d1848f8e5d9f7a05c9b9179df06 refs/pull/75/head +5a523ae50458b89a8b54e7e51180ce01b72e741f refs/pull/75/merge +5cbe5238b52880706fc98b34b8b5c9c74188fa7d refs/pull/77/head +b90a63424bdd9b885b0e8805aec87cfb3303e14b refs/pull/77/merge +031f59fb5c8acfdeef725ce00c6bf4e1dc75e577 refs/pull/78/head +6f75f0ebe8f8f1b325dcec57af45fefbe90582c7 refs/pull/78/merge +1377728fab6c693137445a709b0f9da32517f1c1 refs/pull/79/head +d09814c47592f4bbd70216b24958ee4c4800852b refs/pull/8/head +b4464cf83a3247d92d8537567cb0f084d2da6f45 refs/pull/8/merge +fff4d9b74fa7c914a0ac031c8d22f5ea727bb230 refs/pull/80/head +eee87dc1f557e8e3881431eaf538706c2ac58b51 refs/pull/81/head +fb265dcaaf3363de236541fb5ae24a8532a3f65f refs/pull/84/head +0095ec704786ad017bcb788a380085b092cbb763 refs/pull/84/merge +503690e568314832eac92f8ecad885500a2c52b9 refs/pull/85/head +5409608e84fa0bc21890b957adf0c2626a3c0e0b refs/pull/86/head +906c7d8272d0a29973b646287eb20a3113058a07 refs/pull/87/head +b3295721cde93b97ed572e79243700f2a2194a00 refs/pull/87/merge +866b4ede2be0ad329186afc84dcf655e7beef7ae refs/pull/88/head +067554dd9a4c2e34c5349c5c414c0482cdc9e0a3 refs/pull/89/head +4dd66633544fa2296eea1cbc942435a9b6829971 refs/pull/89/merge +366f3d8674aadadc56a7218da1d13c6a8aae43ae refs/pull/9/head +cad96eb6eabca93071ad9a0a3263b4ef7c7bbe1b refs/pull/9/merge +16028ad5c2edbc42df1ef0d94bfd8a829c26e854 refs/pull/90/head +e1945d4e1d6fba3a267f21b1503801732932f94e refs/pull/94/head +f2e814d923cf75fd13aa4a6ea7cb8132f1d38207 refs/pull/94/merge +2160af80e009b82df6f8a9b727d6c8c5fb7fd02b refs/pull/98/head +9616dd791b4ec12c6243d77b1f0207d890a4ab3f refs/pull/99/head +bb0d846ba7525b64754fa614b75de50e4ad35dbd refs/tags/0.1.0 +6fe7fbc232ad0e8105441f587c58dbf75792541c refs/tags/0.1.1 +10e91dc60f6f7f4fa80d86c7dc9cc7e490878a4c refs/tags/0.1.2 +f3b5e18bc84fbca9de3eeb733b5d04813ab0fb63 refs/tags/0.2.0 +a445ac6d0673e5beea903fcee6020f26e81312d7 refs/tags/0.2.1 +5cea53b6e621f29efd4efbc95a07b3744019af6b refs/tags/0.3.0 +f15d7b4fd35e49dd7a44aa87917ef4a10ca7b6ea refs/tags/0.3.1 +2878c219e2b614743f139cd77d0fc5a6fa4e0960 refs/tags/1.0.0 +9634f6979c129d7834766175b59e8080fe7792bc refs/tags/1.0.1 +78e13a4e23ff5eeaaa84076bb50ccb0a25da89fc refs/tags/1.0.2 +c5ab1242b1bbcd4dc4a366ddc527283f2c7f96f9 refs/tags/1.1.0 +b728196e810534b78ab5206dcee7183c80227e69 refs/tags/1.1.1 +a40dfe1b8d37453a7c0a228c953a313b39040aba refs/tags/1.2.0 +615b4e4a3f15a20b1d37e7bc140e61081bb52470 refs/tags/1.3.0 +9fee1af314e61307ada2eacd4e8b3de1e581ee11 refs/tags/1.3.0^{} +00645ad0766cedb8dd998cc170a981dc82262f8b refs/tags/1.3.1 +cbd64787c744c4f4634ace2b601c9e9517786cfe refs/tags/1.3.2 +5bc109737e0b3b2b1436225ba83c66e12a4fb804 refs/tags/1.3.2^{} +f809df7c043c541e771b3e82d0c0384de8372b8d refs/tags/1.4.0 +d038dfd5b1bff29ffc77e82433dcdf11475eaea1 refs/tags/1.4.0^{} +723b117f57dc8f45c54b5414dd25b40ac8508c1b refs/tags/1.4.1 +452c4fb8755634a017c78636bd3f35f3eab79216 refs/tags/1.4.1^{} +4c7c6417f7318781211a65963ad712129df2bc56 refs/tags/2.0.0 +15f73f05fc6d8b327b5d7852ca0a4239f9893d05 refs/tags/2.0.0^{} +266e96ed2714c5a67ab963989cfadc773e6ab5dc refs/tags/2.0.1 +9f4de0a5fb554ac76a0c5250711546382b6a5828 refs/tags/2.0.1^{} +af30d09f299019f0d868ead4b82ffd2598d27dcf refs/tags/v2.1.0 +178187774fd481cbe7dbabb1833b86b446f56e16 refs/tags/v2.1.1 +7b27d0172d532876a8514de76a13fd139e1ffce7 refs/tags/v2.1.2 +bfd882ff85b4d6568dfe05f4a4401bd1b63de559 refs/tags/v2.2.0 +15d87d78f8f92f118ce5ee9ff88ef1eafe0aca2f refs/tags/v2.3.0 +e5542e2d1df4bc742fd365e34779727ec69f222f refs/tags/v2.4.0 +63d0e8a4ede650490c19e2611e56c037955f2962 refs/tags/v3.0.0 +677625a5d1c197c577d18e35f111d764090bbeab refs/tags/v3.1.0 +99fe9997bf2aa12829d075aa401e6c79ac3b66a5 refs/tags/v3.2.0 +1bc0d26f972ceec8ae8330664e46e6a270ba7cd3 refs/tags/v3.3.0 +d3f5ebb756d4f04dcb32fe18d28fe92e9822d7c6 refs/tags/v3.3.1 +d1ab55a7ebbda5072f3972f73ca5031e30c949fd refs/tags/v3.3.2 +e7c1251536a9e0f7f0b4a9c75a850ec1fb731732 refs/tags/v3.3.3 +b0719ca141f76de586a4c81ac9623ddc9fde655b refs/tags/v3.3.4 +be0e012dc084930a655f105ad6b0ee3e4528a098 refs/tags/v3.4.0 +c11873253aebb047acb86f7fdddc4f3859d7296e refs/tags/v3.4.1 diff --git a/spec/ra10ke/puppetfile_parser_spec.rb b/spec/ra10ke/puppetfile_parser_spec.rb new file mode 100644 index 0000000..f7fab3d --- /dev/null +++ b/spec/ra10ke/puppetfile_parser_spec.rb @@ -0,0 +1,103 @@ +require 'spec_helper' +require 'ra10ke/puppetfile_parser' + +RSpec.describe 'Ra10ke::PuppetfileParser' do + include Ra10ke::PuppetfileParser + + let(:puppetfile) do + File.join(fixtures_dir, 'Puppetfile') + end + + let(:puppetfile_modules) do + [{:args=>{:version=>"2.2.0"}, :name=>"inifile", :namespace=>"puppetlabs"}, + {:args=>{:version=>"4.24.0"}, :name=>"stdlib", :namespace=>"puppetlabs"}, + {:args=>{:version=>"4.0.0"}, :name=>"concat", :namespace=>"puppetlabs"}, + {:args=>{:version=>"6.4.1"}, :name=>"ntp", :namespace=>"puppetlabs"}, + {:args=>{:version=>"3.1.1"}, :name=>"archive", :namespace=>"puppet"}, + {:args=> + {:git=>"https://github.com/vshn/puppet-gitlab", + :ref=>"00397b86dfb3487d9df768cbd3698d362132b5bf"}, + :name=>"gitlab", + :namespace=>nil}, + {:args=>{:git=>"https://github.com/acidprime/r10k", :tag=>"v3.1.1"}, + :name=>"r10k", + :namespace=>nil}, + {:args=> + {:branch=>"gitlab_disable_ssl_verify_support", + :git=>"https://github.com/npwalker/abrader-gms"}, + :name=>"gms", + :namespace=>nil}, + {:args=> + {:git=>"https://github.com/puppetlabs/pltraining-rbac", + :ref=>"2f60e1789a721ce83f8df061e13f8bf81cd4e4ce"}, + :name=>"rbac", + :namespace=>"pltraining"}, + {:args=> + {:branch=>"master", :git=>"https://github.com/dobbymoodge/puppet-acl.git"}, + :name=>"acl", + :namespace=>"puppet"}, + {:args=>{:branch=>"master", :git=>"https://github.com/cudgel/deploy.git"}, + :name=>"deploy", + :namespace=>nil}, + {:args=> + {:branch=>"master", :git=>"https://github.com/cudgel/puppet-dotfiles.git"}, + :name=>"dotfiles", + :namespace=>nil}, + {:args=>{:branch=>"prod", :git=>"https://github.com/cudgel/splunk.git"}, + :name=>"splunk", + :namespace=>nil}] + end + + + it '#modules' do + expect(modules(puppetfile)).to eq(puppetfile_modules) + end + + it '#git_modules' do + expected = [{:args=> + {:git=>"https://github.com/vshn/puppet-gitlab", + :ref=>"00397b86dfb3487d9df768cbd3698d362132b5bf"}, + :name=>"gitlab", + :namespace=>nil}, + {:args=>{:git=>"https://github.com/acidprime/r10k", :tag=>"v3.1.1"}, + :name=>"r10k", + :namespace=>nil}, + {:args=> + {:branch=>"gitlab_disable_ssl_verify_support", + :git=>"https://github.com/npwalker/abrader-gms"}, + :name=>"gms", + :namespace=>nil}, + {:args=> + {:git=>"https://github.com/puppetlabs/pltraining-rbac", + :ref=>"2f60e1789a721ce83f8df061e13f8bf81cd4e4ce"}, + :name=>"rbac", + :namespace=>"pltraining"}, + {:args=> + {:branch=>"master", :git=>"https://github.com/dobbymoodge/puppet-acl.git"}, + :name=>"acl", + :namespace=>"puppet"}, + {:args=>{:branch=>"master", :git=>"https://github.com/cudgel/deploy.git"}, + :name=>"deploy", + :namespace=>nil}, + {:args=> + {:branch=>"master", :git=>"https://github.com/cudgel/puppet-dotfiles.git"}, + :name=>"dotfiles", + :namespace=>nil}, + {:args=>{:branch=>"prod", :git=>"https://github.com/cudgel/splunk.git"}, + :name=>"splunk", + :namespace=>nil}] + expect(git_modules(puppetfile)).to eq(expected) + end + + it '#parse_modules_args' do + data = " 'puppet-acl', :git => 'https://github.com/dobbymoodge/puppet-acl.git', :branch => 'master'" + expect(parse_module_args(data)).to eq({:args=>{:branch=>"master", + :git=>"https://github.com/dobbymoodge/puppet-acl.git"}, + :name=>"acl", :namespace=>"puppet"}) + end + + it '#parse_modules_args when empty' do + data = "" + expect(parse_module_args(data)).to eq({}) + end +end diff --git a/spec/ra10ke/validate_spec.rb b/spec/ra10ke/validate_spec.rb new file mode 100644 index 0000000..b0ed88f --- /dev/null +++ b/spec/ra10ke/validate_spec.rb @@ -0,0 +1,81 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'ra10ke/validate' +RSpec::Mocks.configuration.allow_message_expectations_on_nil = true + +RSpec.describe 'Ra10ke::Validate::Validation' do + let(:instance) do + Ra10ke::Validate::Validation.new(puppetfile) + end + + let(:result) do + double + end + + before(:each) do + allow(result).to receive(:success?).and_return(true) + # allow(instance).to receive(:`).with(anything).and_return(result) + allow($CHILD_STATUS).to receive(:success?).and_return(true) + allow(instance).to receive(:`).with(anything) + .and_return(File.read(File.join(fixtures_dir, 'reflist.txt'))) + end + + let(:puppetfile) do + File.join(fixtures_dir, 'Puppetfile') + end + + it '#new' do + expect(instance).to be_a Ra10ke::Validate::Validation + end + + it '#valid_ref?' do + expect(instance.valid_ref?('https://www.example.com', 'master')).to be true + end + + it '#valid_commit?' do + expect(instance.valid_commit?('https://www.example.com', 'master')).to be true + end + + it '#bad_mods?' do + allow(instance).to receive(:`).with(anything) + .and_return(File.read(File.join(fixtures_dir, 'reflist.txt'))) + # because we can't test every single module we return the same result set + # which only passes for a single module, while others fail. + expect(instance.bad_mods?).to be true + end + + it '#all_modules is an array' do + expect(instance.all_modules).to be_a Array + end + + it '#sorted_mods is an array' do + expect(instance.sorted_mods).to be_a Array + end + + it '#data is a hash' do + expect(instance.all_modules.first).to be_a Hash + end + + it '#data is a hash with keys' do + keys = instance.all_modules.first.keys + expect(keys).to eq(%i[name url ref valid_ref? status]) + end + + it '#data is a hash with values' do + keys = instance.all_modules.first.values + + expect(keys).to eq(['gitlab', 'https://github.com/vshn/puppet-gitlab', + '00397b86dfb3487d9df768cbd3698d362132b5bf', true, '👍']) + end + + it '#all_refs' do + refs = instance.all_refs('https://www.example.com') + expect(refs).to be_a Hash + expect(refs.first).to eq( + ["0ec707e431367bbe2752966be8ab915b6f0da754", + {:name=>"74110ac", :ref=>"refs/heads/74110ac", :subtype=>nil, :type=>:branch}] + ) + + end +end diff --git a/spec/ra10ke_spec.rb b/spec/ra10ke_spec.rb new file mode 100644 index 0000000..3787078 --- /dev/null +++ b/spec/ra10ke_spec.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +require 'ra10ke' +require 'spec_helper' + +RSpec.describe 'Ra10ke::RakeTask' do + let(:instance) do + Ra10ke::RakeTask.new do |t| + t.puppetfile_path = puppetfile + end + end + + let(:puppetfile) do + File.join(fixtures_dir, 'Puppetfile') + end + + let(:args) do + [] + end + + describe 'validate tasks' do + it '#new' do + expect(instance).to be_a Ra10ke::RakeTask + end + + it '#define_task_validate' do + expect(instance.define_task_validate(args)).to be_a Rake::Task + end + + it '#define_task_solve_dependencies' do + expect(instance.define_task_solve_dependencies(args)).to be_a Rake::Task + end + + it '#define_task_syntax' do + expect(instance.define_task_syntax(args)).to be_a Rake::Task + end + + it '#define_task_dependencies' do + expect(instance.define_task_dependencies(args)).to be_a Rake::Task + end + + it '#define_task_install' do + expect(instance.define_task_install(args)).to be_a Rake::Task + end + + it '#get_puppetfile' do + expect(instance.get_puppetfile).to be_a R10K::Puppetfile + end + end + + describe 'run tasks with good refs' do + it '#run_validate_task' do + task = instance.define_task_validate(args) + expect(task.invoke).to be_a Array + end + end + + describe 'run tasks with bad refs' do + let(:puppetfile) do + File.join(fixtures_dir, 'Puppetfile_with_bad_refs') + end + + # I suspect rake is caching something here and the puppetfile is + # not being sent correctly as it is not using the file I specify. + # The output should be different. + # Testing this by itself works + it '#run_validate_task' do + t = Ra10ke::RakeTask.new + task2 = t.define_task_validate(args) + expect(task2.invoke).to be nil + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..cc0e90b --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,3 @@ +def fixtures_dir + File.join(__dir__, 'fixtures') +end