<commit_before>require 'spec_helper'

describe BackupJob do
  it "should build a valid main rsync command line" do
    s = FactoryGirl.build(:server, :hostname => 'server1.example.com')
    p = FactoryGirl.build(:profile, :name => 'linux')
    p.includes << FactoryGirl.build(:include, :path => '/')
    p.excludes << FactoryGirl.build(:exclude, :path => '/backup')
    p.splits << FactoryGirl.build(:split, :path => '/home')
    s.profiles << p
    j = FactoryGirl.build(:backup_job, :server => s)
    expect(j.main_rsync).to be == "/usr/bin/pfexec rsync --stats -aHRW --numeric-ids --timeout=3600 --delete-excluded --exclude=.zfs -e 'ssh -c arcfour -p 22' --filter='protect /home' --include=/ --exclude=/home --exclude=/backup server1.example.com:/ /backup/server1.example.com/"
  end

  it "should store a list of rsyncs" do
    s = FactoryGirl.build(:server, :hostname => 'server1.example.com')
    p = FactoryGirl.build(:profile, :name => 'linux')
    p.includes << FactoryGirl.build(:include, :path => '/')
    p.excludes << FactoryGirl.build(:exclude, :path => '/backup')
    p.splits << FactoryGirl.build(:split, :path => '/home')
    s.profiles << p
    j = FactoryGirl.build(:backup_job, :server => s)
    j.rsyncs.size.should == 62 # a-z,A-Z,0-9
    j.rsyncs.first.should == "/usr/bin/pfexec rsync --stats -aHRW --numeric-ids --timeout=3600 --delete-excluded --exclude=.zfs -e 'ssh -c arcfour -p 22' --filter='protect /home' --include=/ --exclude=/backup server1.example.com://home/a* /backup/server1.example.com/"
    j.rsyncs.last.should == "/usr/bin/pfexec rsync --stats -aHRW --numeric-ids --timeout=3600 --delete-excluded --exclude=.zfs -e 'ssh -c arcfour -p 22' --filter='protect /home' --include=/ --exclude=/backup server1.example.com://home/9* /backup/server1.example.com/"
  end

  it "should store more rsyncs if the depth is 2" do
    s = FactoryGirl.build(:server, :hostname => 'server1.example.com')
    p = FactoryGirl.build(:profile, :name => 'linux')
    p.includes << FactoryGirl.build(:include, :path => '/')
    p.excludes << FactoryGirl.build(:exclude, :path => '/backup')
    p.splits << FactoryGirl.build(:split, :path => '/home', :depth => 2)
    s.profiles << p
    j = FactoryGirl.build(:backup_job, :server => s)
    j.rsyncs.size.should == 3844 # a-z,A-Z,0-9
    j.rsyncs.first.should == "/usr/bin/pfexec rsync --stats -aHRW --numeric-ids --timeout=3600 --delete-excluded --exclude=.zfs -e 'ssh -c arcfour -p 22' --filter='protect /home' --include=/ --exclude=/backup server1.example.com://home/a*/a* /backup/server1.example.com/"
    j.rsyncs.last.should == "/usr/bin/pfexec rsync --stats -aHRW --numeric-ids --timeout=3600 --delete-excluded --exclude=.zfs -e 'ssh -c arcfour -p 22' --filter='protect /home' --include=/ --exclude=/backup server1.example.com://home/9*/9* /backup/server1.example.com/"
  end

  it "should not add splits if there is a matching include" do
    s = FactoryGirl.build(:server, :hostname => 'server1.example.com')
    p = FactoryGirl.build(:profile, :name => 'linux')
    p.includes << FactoryGirl.build(:include, :path => '/')
    p.excludes << FactoryGirl.build(:exclude, :path => '/home')
    p.splits << FactoryGirl.build(:split, :path => '/home')
    s.profiles << p
    j = FactoryGirl.build(:backup_job, :server => s)
    j.rsyncs.size.should == 0
  end<commit_msg>match test suite to suit<commit_after>require 'spec_helper'

describe BackupJob do
  it "should build a valid main rsync command line" do
    s = FactoryGirl.build(:server, :hostname => 'server1.example.com')
    p = FactoryGirl.build(:profile, :name => 'linux')
    p.includes << FactoryGirl.build(:include, :path => '/')
    p.excludes << FactoryGirl.build(:exclude, :path => '/backup')
    p.splits << FactoryGirl.build(:split, :path => '/home')
    s.profiles << p
    j = FactoryGirl.build(:backup_job, :server => s)
    expect(j.main_rsync).to be == "/usr/bin/pfexec rsync --stats -aHRW --numeric-ids --timeout=3600 --delete-excluded --exclude=.zfs -e 'ssh -c arcfour,aes128-ctr -p 22' --filter='protect /home' --include=/ --exclude=/home --exclude=/backup server1.example.com:/ /backup/server1.example.com/"
  end

  it "should store a list of rsyncs" do
    s = FactoryGirl.build(:server, :hostname => 'server1.example.com')
    p = FactoryGirl.build(:profile, :name => 'linux')
    p.includes << FactoryGirl.build(:include, :path => '/')
    p.excludes << FactoryGirl.build(:exclude, :path => '/backup')
    p.splits << FactoryGirl.build(:split, :path => '/home')
    s.profiles << p
    j = FactoryGirl.build(:backup_job, :server => s)
    j.rsyncs.size.should == 62 # a-z,A-Z,0-9
    j.rsyncs.first.should == "/usr/bin/pfexec rsync --stats -aHRW --numeric-ids --timeout=3600 --delete-excluded --exclude=.zfs -e 'ssh -c arcfour,aes128-ctr -p 22' --filter='protect /home' --include=/ --exclude=/backup server1.example.com://home/a* /backup/server1.example.com/"
    j.rsyncs.last.should == "/usr/bin/pfexec rsync --stats -aHRW --numeric-ids --timeout=3600 --delete-excluded --exclude=.zfs -e 'ssh -c arcfour,aes128-ctr -p 22' --filter='protect /home' --include=/ --exclude=/backup server1.example.com://home/9* /backup/server1.example.com/"
  end

  it "should store more rsyncs if the depth is 2" do
    s = FactoryGirl.build(:server, :hostname => 'server1.example.com')
    p = FactoryGirl.build(:profile, :name => 'linux')
    p.includes << FactoryGirl.build(:include, :path => '/')
    p.excludes << FactoryGirl.build(:exclude, :path => '/backup')
    p.splits << FactoryGirl.build(:split, :path => '/home', :depth => 2)
    s.profiles << p
    j = FactoryGirl.build(:backup_job, :server => s)
    j.rsyncs.size.should == 3844 # a-z,A-Z,0-9
    j.rsyncs.first.should == "/usr/bin/pfexec rsync --stats -aHRW --numeric-ids --timeout=3600 --delete-excluded --exclude=.zfs -e 'ssh -c arcfour,aes128-ctr -p 22' --filter='protect /home' --include=/ --exclude=/backup server1.example.com://home/a*/a* /backup/server1.example.com/"
    j.rsyncs.last.should == "/usr/bin/pfexec rsync --stats -aHRW --numeric-ids --timeout=3600 --delete-excluded --exclude=.zfs -e 'ssh -c arcfour,aes128-ctr -p 22' --filter='protect /home' --include=/ --exclude=/backup server1.example.com://home/9*/9* /backup/server1.example.com/"
  end

  it "should not add splits if there is a matching include" do
    s = FactoryGirl.build(:server, :hostname => 'server1.example.com')
    p = FactoryGirl.build(:profile, :name => 'linux')
    p.includes << FactoryGirl.build(:include, :path => '/')
    p.excludes << FactoryGirl.build(:exclude, :path => '/home')
    p.splits << FactoryGirl.build(:split, :path => '/home')
    s.profiles << p
    j = FactoryGirl.build(:backup_job, :server => s)
    j.rsyncs.size.should == 0
  end
{'fraction_non_alphanumeric': 0.19329973317521496, 'fraction_numerical': 0.020011858879335903, 'mean_word_length': 3.2756653992395437, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 53, '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': '3492981', 'n_tokens_mistral': 2515, 'n_tokens_neox': 2326, 'n_words': 537}