bryanwb / chef-ark

An archive unpacker and installer
59 stars 20 forks source link

Unit tests for parse_file_extension #41

Open xpe opened 11 years ago

xpe commented 11 years ago

I didn't see any unit tests for this method. Is this intentional?

      def parse_file_extension
        if new_resource.extension.nil?
          # purge any trailing redirect
          url = new_resource.url.clone
          url =~ /^https?:\/\/.*(.gz|bz2|bin|zip|jar|tgz|tbz)(\/.*\/)/
          url.gsub!($2, '') unless $2.nil?
          # remove tailing query string
          release_basename = ::File.basename(url.gsub(/\?.*\z/, '')).gsub(/-bin\b/, '')
          # (\?.*)? accounts for a trailing querystring
          Chef::Log.debug("DEBUG: release_basename is #{release_basename}")
          release_basename =~ %r{^(.+?)\.(tar\.gz|tar\.bz2|zip|war|jar|tgz|tbz)(\?.*)?}
          Chef::Log.debug("DEBUG: file_extension is #{$2}")
          new_resource.extension = $2
        end
        new_resource.extension
      end

Where would I go about adding unit tests? I'd like to demonstrate that the regexes are pretty brittle. For example, this does not match: "http://eclipse.org/downloads/download.php?file=/jetty/stable-9/dist/jetty-distribution-9.0.6.v20130930.tar.gz&r=1".