Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/zipper_spec.rb
1864 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
require_relative 'spec_helper'
21
22
module Selenium
23
module WebDriver
24
describe Zipper do
25
let(:base_file_name) { 'file.txt' }
26
let(:file_content) { 'content' }
27
let(:zip_file) { File.join(Dir.tmpdir, 'test.zip') }
28
let(:dir_to_zip) { Dir.mktmpdir('webdriver-spec-zipper') }
29
30
def create_file
31
filename = File.join(dir_to_zip, base_file_name)
32
File.open(filename, 'w') { |io| io << file_content }
33
34
filename
35
end
36
37
after { FileUtils.rm_rf zip_file }
38
39
describe '#zip' do
40
it 'a file' do
41
File.open(zip_file, 'wb') do |io|
42
io << Base64.decode64(described_class.zip_file(create_file))
43
end
44
45
expect(File).to exist(zip_file)
46
end
47
48
it 'a folder' do
49
create_file
50
51
File.open(zip_file, 'wb') do |io|
52
io << Base64.decode64(described_class.zip(dir_to_zip))
53
end
54
55
expect(File).to exist(zip_file)
56
end
57
58
it 'follows symlinks' do
59
filename = create_file
60
File.symlink(filename, File.join(dir_to_zip, 'link'))
61
62
zip_file = File.join(Dir.tmpdir, 'test.zip')
63
File.open(zip_file, 'wb') do |io|
64
io << Base64.decode64(described_class.zip(dir_to_zip))
65
end
66
67
unzipped = described_class.unzip(zip_file)
68
expect(File.read(File.join(unzipped, 'link'))).to eq(file_content)
69
end
70
end
71
72
describe '#unzip' do
73
it 'a file' do
74
File.open(zip_file, 'wb') do |io|
75
io << Base64.decode64(described_class.zip_file(create_file))
76
end
77
78
unzipped = described_class.unzip(zip_file)
79
expect(File.read(File.join(unzipped, base_file_name))).to eq(file_content)
80
end
81
82
it 'a folder' do
83
create_file
84
85
File.open(zip_file, 'wb') do |io|
86
io << Base64.decode64(described_class.zip(dir_to_zip))
87
end
88
89
unzipped = described_class.unzip(zip_file)
90
expect(File.read(File.join(unzipped, base_file_name))).to eq(file_content)
91
end
92
end
93
end # Zipper
94
end # WebDriver
95
end # Selenium
96
97