diff --git a/lib/gems/pending/util/object_storage/miq_ftp_storage.rb b/lib/gems/pending/util/object_storage/miq_ftp_storage.rb index c6429c006..da81a0d16 100644 --- a/lib/gems/pending/util/object_storage/miq_ftp_storage.rb +++ b/lib/gems/pending/util/object_storage/miq_ftp_storage.rb @@ -32,6 +32,11 @@ def download(*download_args) with_connection { super } end + # Override for connection handling + def magic_number_for(*magic_number_for_args) + with_connection { super } + end + # Specific version of Net::FTP#storbinary that doesn't use an existing local # file, and only uploads a specific size (byte_count) from the input_file def upload_single(dest_uri) diff --git a/spec/util/object_storage/miq_ftp_storage_spec.rb b/spec/util/object_storage/miq_ftp_storage_spec.rb index 27824b12b..09d3e2e82 100644 --- a/spec/util/object_storage/miq_ftp_storage_spec.rb +++ b/spec/util/object_storage/miq_ftp_storage_spec.rb @@ -115,21 +115,26 @@ # Nothing written, just printed the streamed file in the above command expect(source_data.size).to eq(10.megabytes) end + end - # Note, we are using `#download` in the spec, but really, this is a feature - # for `#download_single`. `#download` really doesn't make use of this - # directly. - it "respects the `byte_count` attribute" do - downloaded_data = StringIO.new - subject.instance_variable_set(:@byte_count, 42) - subject.download(downloaded_data, source_path) + describe "#magic_number_for" do + let(:source_file) { existing_ftp_file(10.megabytes) } + let(:source_path) { File.basename(source_file.path) } - # Sanity check that what we are downloading is the size we expect - expect(source_path).to exist_on_ftp_server - expect(source_path).to have_size_on_ftp_server_of(10.megabytes) + it "returns 256 bytes by default" do + result = subject.magic_number_for(source_path) + + expect(result.size).to eq(256) + expect(result).to eq("0" * 256) + end - expect(downloaded_data.string.size).to eq(42) - expect(downloaded_data.string).to eq("0" * 42) + describe "with a hash of accepted magics" do + it "returns key for the passed in magic number value" do + magics = { :zero => "000", :one => "1", :foo => "bar" } + result = subject.magic_number_for(source_path, :accepted => magics) + + expect(result).to eq(:zero) + end end end end