Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests for parse_file_extension #41

Open
xpe opened this issue Nov 7, 2013 · 0 comments
Open

Unit tests for parse_file_extension #41

xpe opened this issue Nov 7, 2013 · 0 comments

Comments

@xpe
Copy link

xpe commented Nov 7, 2013

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant