-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11907 from jasonwbarnett/feature/add-component-strip
Add strip_components property to archive_file
- Loading branch information
Showing
5 changed files
with
529 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# | ||
# Copyright:: Copyright (c) Chef Software Inc. | ||
# License:: Apache License, Version 2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
require "spec_helper" | ||
require "tmpdir" | ||
|
||
# Excluding this test on Windows until CI issues can be addressed. | ||
describe Chef::Resource::ArchiveFile, :not_supported_on_windows do | ||
include RecipeDSLHelper | ||
|
||
let(:tmp_path) { Dir.mktmpdir } | ||
let(:extract_destination) { "#{tmp_path}/extract_here" } | ||
let(:test_archive_path) { File.expand_path("archive_file/test_archive.tar.gz", CHEF_SPEC_DATA) } | ||
|
||
after do | ||
FileUtils.remove_entry_secure(extract_destination) if File.exist?(extract_destination) | ||
end | ||
|
||
context "when strip_components is 0" do | ||
it "extracts archive to destination" do | ||
af = archive_file test_archive_path do | ||
destination extract_destination | ||
end | ||
af.should_be_updated | ||
|
||
expect(af.strip_components).to eq(0) # Validate defaults haven't changed here | ||
expect(Dir.glob("#{extract_destination}/**/*").length).to eq(4) | ||
expect(Dir.exist?("#{extract_destination}/folder-1")).to eq(true) | ||
expect(File.exist?("#{extract_destination}/folder-1/file-1.txt")).to eq(true) | ||
expect(Dir.exist?("#{extract_destination}/folder-1/folder-2")).to eq(true) | ||
expect(File.exist?("#{extract_destination}/folder-1/folder-2/file-2.txt")).to eq(true) | ||
end | ||
end | ||
|
||
context "when strip_components is 1" do | ||
it "extracts archive to destination, with 1 component stripped" do | ||
archive_file test_archive_path do | ||
destination extract_destination | ||
strip_components 1 | ||
end.should_be_updated | ||
|
||
expect(Dir.exist?("#{extract_destination}/folder-1")).to eq(false) | ||
expect(File.exist?("#{extract_destination}/folder-1/file-1.txt")).to eq(false) | ||
expect(Dir.exist?("#{extract_destination}/folder-1/folder-2")).to eq(false) | ||
expect(File.exist?("#{extract_destination}/folder-1/folder-2/file-2.txt")).to eq(false) | ||
|
||
expect(Dir.glob("#{extract_destination}/**/*").length).to eq(3) | ||
expect(File.exist?("#{extract_destination}/file-1.txt")).to eq(true) | ||
expect(Dir.exist?("#{extract_destination}/folder-2")).to eq(true) | ||
expect(File.exist?("#{extract_destination}/folder-2/file-2.txt")).to eq(true) | ||
end | ||
end | ||
|
||
context "when strip_components is 2" do | ||
it "extracts archive to destination, with 2 components stripped" do | ||
archive_file test_archive_path do | ||
destination extract_destination | ||
strip_components 2 | ||
end.should_be_updated | ||
|
||
expect(Dir.exist?("#{extract_destination}/folder-1")).to eq(false) | ||
expect(File.exist?("#{extract_destination}/folder-1/file-1.txt")).to eq(false) | ||
expect(Dir.exist?("#{extract_destination}/folder-1/folder-2")).to eq(false) | ||
expect(File.exist?("#{extract_destination}/folder-1/folder-2/file-2.txt")).to eq(false) | ||
expect(File.exist?("#{extract_destination}/file-1.txt")).to eq(false) | ||
expect(Dir.exist?("#{extract_destination}/folder-2")).to eq(false) | ||
expect(File.exist?("#{extract_destination}/folder-2/file-2.txt")).to eq(false) | ||
|
||
expect(Dir.glob("#{extract_destination}/**/*").length).to eq(1) | ||
expect(File.exist?("#{extract_destination}/file-2.txt")).to eq(true) | ||
end | ||
end | ||
end |
Oops, something went wrong.