PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/gems/pending/spec/util/miq-file_spec.rb

https://gitlab.com/aljesusg/manageiqtest
Ruby | 50 lines | 42 code | 8 blank | 0 comment | 0 complexity | c21f81728aecec6ef539f2b6fcbb879b MD5 | raw file
  1. require 'uri'
  2. require 'util/extensions/miq-file'
  3. describe 'MIQFile' do
  4. context 'path_to_uri' do
  5. let(:hostname) { MiqSockUtil.getFullyQualifiedDomainName }
  6. it 'is defined and returns a string' do
  7. expect(File).to respond_to(:path_to_uri)
  8. expect(File.path_to_uri('foo')).to be_kind_of(String)
  9. end
  10. it 'returns the expected result' do
  11. expect(File.path_to_uri('foo')).to eql("file://#{hostname}/foo")
  12. expect(File.path_to_uri('foo/bar')).to eql("file://#{hostname}/foo/bar")
  13. expect(File.path_to_uri('foo/bar-stuff')).to eql("file://#{hostname}/foo/bar-stuff")
  14. expect(File.path_to_uri('foo/C:/bar')).to eql("file://#{hostname}/foo/C:/bar")
  15. expect(File.path_to_uri('foo/[bar]')).to eql("file://#{hostname}/foo/%5Bbar%5D")
  16. end
  17. it 'accepts an optional hostname and returns the expected result' do
  18. hostname = 'dell-r410-01.manageiqwin.lab.example.com'
  19. expect(File.path_to_uri('foo', hostname)).to eql("file://#{hostname}/foo")
  20. expect(File.path_to_uri('foo/bar', hostname)).to eql("file://#{hostname}/foo/bar")
  21. expect(File.path_to_uri('foo/bar-stuff', hostname)).to eql("file://#{hostname}/foo/bar-stuff")
  22. expect(File.path_to_uri('foo/C:/bar', hostname)).to eql("file://#{hostname}/foo/C:/bar")
  23. expect(File.path_to_uri('foo/[bar]', hostname)).to eql("file://#{hostname}/foo/%5Bbar%5D")
  24. end
  25. it 'handles an IPv6 hostname as expected' do
  26. hostname = '::1'
  27. expect(File.path_to_uri('foo', hostname)).to eql("file://[#{hostname}]/foo")
  28. end
  29. it 'handles a UNC path as expected' do
  30. file = "//foo/bar/baz"
  31. expect(File.path_to_uri(file, hostname)).to eql("file://#{hostname}/#{file}")
  32. end
  33. it 'handles a volume name as expected' do
  34. file = "///?/Volume{xxx-yyy-42zzz-1111-222233334444}/"
  35. encoded_file = URI.encode(file)
  36. expect(File.path_to_uri(file, hostname)).to eql("file://#{hostname}/#{encoded_file}")
  37. end
  38. it 'requires at least one argument' do
  39. expect { File.path_to_uri }.to raise_error(ArgumentError)
  40. end
  41. end
  42. end