spec/unit/packagers/deb_spec.rb in omnibus-5.5.0 vs spec/unit/packagers/deb_spec.rb in omnibus-5.6.0

- old
+ new

@@ -28,11 +28,11 @@ allow(subject).to receive(:staging_dir).and_return(staging_dir) create_directory(staging_dir) create_directory("#{staging_dir}/DEBIAN") end - describe '#vendor' do + describe "#vendor" do it "is a DSL method" do expect(subject).to have_exposed_method(:vendor) end it "has a default value" do @@ -42,11 +42,11 @@ it "must be a string" do expect { subject.vendor(Object.new) }.to raise_error(InvalidValue) end end - describe '#license' do + describe "#license" do it "is a DSL method" do expect(subject).to have_exposed_method(:license) end it "has a default value" do @@ -64,11 +64,11 @@ expect(subject.license).to eq("custom-license") end end end - describe '#priority' do + describe "#priority" do it "is a DSL method" do expect(subject).to have_exposed_method(:priority) end it "has a default value" do @@ -78,11 +78,11 @@ it "must be a string" do expect { subject.priority(Object.new) }.to raise_error(InvalidValue) end end - describe '#section' do + describe "#section" do it "is a DSL method" do expect(subject).to have_exposed_method(:section) end it "has a default value" do @@ -92,33 +92,75 @@ it "must be a string" do expect { subject.section(Object.new) }.to raise_error(InvalidValue) end end - describe '#id' do + describe "#compression_type" do + it "is a DSL method" do + expect(subject).to have_exposed_method(:compression_type) + end + + it "has a default value" do + expect(subject.compression_type).to eq(:gzip) + end + + it "must be a symbol" do + expect { subject.compression_type(Object.new) }.to raise_error(InvalidValue) + end + end + + describe "#compression_level" do + it "is a DSL method" do + expect(subject).to have_exposed_method(:compression_level) + end + + it "has a default value" do + expect(subject.compression_level).to eq(9) + end + + it "must be a symbol" do + expect { subject.compression_level(Object.new) }.to raise_error(InvalidValue) + end + end + + describe "#compression_strategy" do + it "is a DSL method" do + expect(subject).to have_exposed_method(:compression_strategy) + end + + it "has a default value" do + expect(subject.compression_strategy).to eq(nil) + end + + it "must be a symbol" do + expect { subject.compression_strategy(Object.new) }.to raise_error(InvalidValue) + end + end + + describe "#id" do it "is :deb" do expect(subject.id).to eq(:deb) end end - describe '#package_name' do + describe "#package_name" do before do allow(subject).to receive(:safe_architecture).and_return("amd64") end it "includes the name, version, and build iteration" do expect(subject.package_name).to eq("project_1.2.3-2_amd64.deb") end end - describe '#debian_dir' do + describe "#debian_dir" do it "is nested inside the staging_dir" do expect(subject.debian_dir).to eq("#{staging_dir}/DEBIAN") end end - describe '#write_control_file' do + describe "#write_control_file" do before do allow(subject).to receive(:safe_architecture).and_return("amd64") end it "generates the file" do @@ -142,11 +184,11 @@ expect(contents).to include("Homepage: https://example.com") expect(contents).to include("Description: The full stack of project") end end - describe '#write_conffiles_file' do + describe "#write_conffiles_file" do before do project.config_file("/opt/project/file1") project.config_file("/opt/project/file2") end @@ -171,11 +213,11 @@ expect(contents).to include("/opt/project/file1") expect(contents).to include("/opt/project/file2") end end - describe '#write_scripts' do + describe "#write_scripts" do before do create_file("#{project_root}/package-scripts/project/preinst") { "preinst" } create_file("#{project_root}/package-scripts/project/postinst") { "postinst" } create_file("#{project_root}/package-scripts/project/prerm") { "prerm" } create_file("#{project_root}/package-scripts/project/postrm") { "postrm" } @@ -205,11 +247,11 @@ expect(output).to include("Adding script `prerm'") expect(output).to include("Adding script `postrm'") end end - describe '#write_md5_sums' do + describe "#write_md5_sums" do before do create_file("#{staging_dir}/.filea") { ".filea" } create_file("#{staging_dir}/file1") { "file1" } create_file("#{staging_dir}/file2") { "file2" } create_file("#{staging_dir}/DEBIAN/preinst") { "preinst" } @@ -232,11 +274,11 @@ expect(contents).to_not include("DEBIAN/preinst") expect(contents).to_not include("DEBIAN/postrm") end end - describe '#create_deb_file' do + describe "#create_deb_file" do before do allow(subject).to receive(:shellout!) allow(Dir).to receive(:chdir) { |_, &b| b.call } allow(subject).to receive(:safe_architecture).and_return("amd64") end @@ -255,13 +297,49 @@ it "uses the correct command" do expect(subject).to receive(:shellout!) .with(/dpkg-deb -z9 -Zgzip -D --build/) subject.create_deb_file end + + describe "when deb compression type xz is configured" do + before do + subject.compression_type(:xz) + end + + it "uses the correct command for xz" do + expect(subject).to receive(:shellout!) + .with(/dpkg-deb -z9 -Zxz -D --build/) + subject.create_deb_file + end + + context "when deb compression level is configured" do + before do + subject.compression_level(6) + end + + it "uses the correct command for xz" do + expect(subject).to receive(:shellout!) + .with(/dpkg-deb -z6 -Zxz -D --build/) + subject.create_deb_file + end + end + + context "when deb compression strategy is configured" do + before do + subject.compression_strategy(:extreme) + end + + it "uses the correct command for xz" do + expect(subject).to receive(:shellout!) + .with(/dpkg-deb -z9 -Zxz -Sextreme -D --build/) + subject.create_deb_file + end + end + end end - describe '#package_size' do + describe "#package_size" do before do project.install_dir(staging_dir) create_file("#{staging_dir}/file1") { "1" * 10_000 } create_file("#{staging_dir}/file2") { "2" * 20_000 } @@ -270,11 +348,11 @@ it "stats all the files in the install_dir" do expect(subject.package_size).to eq(29) end end - describe '#safe_base_package_name' do + describe "#safe_base_package_name" do context 'when the project name is "safe"' do it "returns the value without logging a message" do expect(subject.safe_base_package_name).to eq("project") expect(subject).to_not receive(:log) end @@ -291,17 +369,17 @@ expect(output).to include("The `name' component of Debian package names can only include") end end end - describe '#safe_build_iteration' do + describe "#safe_build_iteration" do it "returns the build iteration" do expect(subject.safe_build_iteration).to eq(project.build_iteration) end end - describe '#safe_version' do + describe "#safe_version" do context 'when the project build_version is "safe"' do it "returns the value without logging a message" do expect(subject.safe_version).to eq("1.2.3") expect(subject).to_not receive(:log) end @@ -330,10 +408,10 @@ expect(output).to include("The `version' component of Debian package names can only include") end end end - describe '#safe_architecture' do + describe "#safe_architecture" do let(:shellout) { double("Mixlib::ShellOut", :run_command => true, :error! => nil) } before do allow(Mixlib::ShellOut).to receive(:new).and_return(shellout) end