Skip to content

Commit

Permalink
Fix managed directory test on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
hainesr committed Feb 11, 2025
1 parent e74d878 commit f9e4b1b
Showing 1 changed file with 45 additions and 15 deletions.
60 changes: 45 additions & 15 deletions test/managed_entries_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
require_relative 'test_helper'

require 'tmpdir'
require 'os'
require 'zip-container/dir'
require 'zip-container/file'
require 'zip-container/managed_directory'
Expand Down Expand Up @@ -173,21 +174,10 @@ def test_verify_subclassed_dir_container
# Create a subclassed container. Check it doesn't verify at first; satisfy
# the conditions; then assert that it verifies correctly.
def test_create_subclassed_dir_container
Dir.mktmpdir do |dir|
filename = File.join(dir, 'test.container')

ExampleDirContainer.create(filename, MIMETYPE) do |c|
assert_raises(ZipContainer::MalformedContainerError) do
c.verify!
end

Dir.mkdir(File.join(filename, 'dir'))
File.open(File.join(filename, 'greeting.txt'), 'w') do |f|
f.puts 'Yo means hello.'
end

c.verify!
end
if OS.windows?
create_subclassed_dir_container_test_windows
else
create_subclassed_dir_container_test
end
end

Expand Down Expand Up @@ -408,4 +398,44 @@ def test_create_subclassed_container_with_deep_content_verification
ExampleZipContainer2.verify!(filename)
end
end

private

def create_subclassed_dir_container_test
Dir.mktmpdir do |dir|
filename = File.join(dir, 'test.container')

ExampleDirContainer.create(filename, MIMETYPE) do |c|
assert_raises(ZipContainer::MalformedContainerError) do
c.verify!
end

Dir.mkdir(File.join(filename, 'dir'))
File.open(File.join(filename, 'greeting.txt'), 'w') do |f|
f.puts 'Yo means hello.'
end

c.verify!
end
end
end

def create_subclassed_dir_container_test_windows
Dir.mktmpdir do |dir|
filename = File.join(dir, 'test.container')

ExampleDirContainer.create(filename, MIMETYPE) do |c|
assert_raises(ZipContainer::MalformedContainerError) do
c.verify!
end

Dir.mkdir(File.join(filename, 'dir'))
File.open(File.join(filename, 'greeting.txt'), 'w') do |f|
f.puts 'Yo means hello.'
end
end

ExampleDirContainer.verify!(filename)
end
end
end

0 comments on commit f9e4b1b

Please sign in to comment.