<commit_before>require 'spec_helper'
require 'blobstore_client'

describe Bosh::Director::Jobs::Backup do
  let(:backup_file) { '/dest_dir/backup.tgz' }
  let(:tar_gzipper) { double('tar gzipper') }
  let(:blobstore_client) { double(Bosh::Blobstore::Client) }
  let(:db_adapter) { double('db adapter') }
  let(:backup_task) do
    described_class.new(backup_file,
                        tar_gzipper: tar_gzipper,
                        blobstore: blobstore_client,
                        db_adapter: db_adapter)
  end

  describe 'described_class.job_type' do
    it 'returns a symbol representing job type' do
      expect(described_class.job_type).to eq(:bosh_backup)
    end
  end

  context '#backup_logs' do
    let(:log_directory) { '/var/vcap/sys/log' }

    it "zips up the logs" do
      tar_gzipper.should_receive(:compress).with(log_directory, '/foo/logs.tgz')
      expect(backup_task.backup_logs('/foo')).to eq('/foo/logs.tgz')
    end
  end

  context '#backup_task_logs' do
    let(:task_log_directory) { '/var/vcap/store/director/tasks' }

    it "zips up the task logs" do
      tar_gzipper.should_receive(:compress).with(task_log_directory, '/foo/task_logs.tgz')
      expect(backup_task.backup_task_logs('/foo')).to eq('/foo/task_logs.tgz')
    end
  end

  it 'backs up the database' do
    db_adapter.should_receive(:export).with('/foo/director_db.sql')

    expect(backup_task.backup_database('/foo')).to eq('/foo/director_db.sql')
  end

  context 'backing up the blobstore' do
    before do
      Dir.stub(:mkdir)
    end

    it 'backs up the blobstore' do
      fooFile = double(File)
      barFile = double(File)
      fooFile.stub(:path).and_return('foo')
      barFile.stub(:path).and_return('bar')
      File.should_receive(:open).with('/tmpdir/blobs/foo', 'w').and_yield(fooFile)
      File.should_receive(:open).with('/tmpdir/blobs/bar', 'w').and_yield(barFile)
<commit_msg>Use single quotes for uninterpolated strings<commit_after>require 'spec_helper'
require 'blobstore_client'

describe Bosh::Director::Jobs::Backup do
  let(:backup_file) { '/dest_dir/backup.tgz' }
  let(:tar_gzipper) { double('tar gzipper') }
  let(:blobstore_client) { double(Bosh::Blobstore::Client) }
  let(:db_adapter) { double('db adapter') }
  let(:backup_task) do
    described_class.new(backup_file,
                        tar_gzipper: tar_gzipper,
                        blobstore: blobstore_client,
                        db_adapter: db_adapter)
  end

  describe 'described_class.job_type' do
    it 'returns a symbol representing job type' do
      expect(described_class.job_type).to eq(:bosh_backup)
    end
  end

  context '#backup_logs' do
    let(:log_directory) { '/var/vcap/sys/log' }

    it 'zips up the logs' do
      tar_gzipper.should_receive(:compress).with(log_directory, '/foo/logs.tgz')
      expect(backup_task.backup_logs('/foo')).to eq('/foo/logs.tgz')
    end
  end

  context '#backup_task_logs' do
    let(:task_log_directory) { '/var/vcap/store/director/tasks' }

    it 'zips up the task logs' do
      tar_gzipper.should_receive(:compress).with(task_log_directory, '/foo/task_logs.tgz')
      expect(backup_task.backup_task_logs('/foo')).to eq('/foo/task_logs.tgz')
    end
  end

  it 'backs up the database' do
    db_adapter.should_receive(:export).with('/foo/director_db.sql')

    expect(backup_task.backup_database('/foo')).to eq('/foo/director_db.sql')
  end

  context 'backing up the blobstore' do
    before do
      Dir.stub(:mkdir)
    end

    it 'backs up the blobstore' do
      fooFile = double(File)
      barFile = double(File)
      fooFile.stub(:path).and_return('foo')
      barFile.stub(:path).and_return('bar')
      File.should_receive(:open).with('/tmpdir/blobs/foo', 'w').and_yield(fooFile)
      File.should_receive(:open).with('/tmpdir/blobs/bar', 'w').and_yield(barFile)

{'fraction_non_alphanumeric': 0.13769810340348143, 'fraction_numerical': 0.0, 'mean_word_length': 3.415137614678899, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5548767', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1286, 'n_words': 231}