Skip to content

[CI] Print expected file path when backup specs fail

Mitchell Nielsen requested to merge 2942-backup-specs-add-debug-info into master

What does this MR do?

Adds a debug line to print out the expected file path when comparing the test backup to the original backup.

This should help give us more information when the test fails, which led to #2942 (closed).

Related issues

Related to #2942 (closed).

Testing

As this MR modifies a job that only runs on master, I ran a brief local test to validate syntax and expected output:

Script to prepare the environment

#!/bin/bash

# Create empty backup directories
mkdir -p tmp/{original_backup,test_backup}

# Put matching files in both directories
echo "Hello" > tmp/{original_backup,test_backup}/hello.txt

# Put a unique file in the original backup directory
echo "World" > tmp/original_backup/world.txt

Isolated spec using the changes in this MR

require 'spec_helper'

describe "Restoring a backup" do
  describe 'Backups' do
    it 'Should be able to backup an identical tar' do
      Dir.glob("tmp/original_backup/*") do |file|
        file_path = "tmp/test_backup/#{File.basename(file)}"
        expect(File.exist?(file_path)).to be_truthy, "Expected #{file_path} to exist"
      end
    end
  end
end

Results

$ bundle exec rspec -c -f d test_spec.rb -t ~type:feature
warning: parser/current is loading parser/ruby26, which recognizes
warning: 2.6.6-compliant syntax, but you are running 2.6.3.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
Run options:
  include {:focus=>true}
  exclude {:type=>"feature"}

All examples were filtered out; ignoring {:focus=>true}

Restoring a backup
  Backups
    Should be able to backup an identical tar (FAILED - 1)

Failures:

  1) Restoring a backup Backups Should be able to backup an identical tar
     Failure/Error: expect(File.exist?(file_path)).to be_truthy, "Expected #{file_path} to exist"
       Expected tmp/test_backup/world.txt to exist
     # ./test_spec.rb:9:in `block (4 levels) in <top (required)>'
     # ./test_spec.rb:7:in `glob'
     # ./test_spec.rb:7:in `block (3 levels) in <top (required)>'
     # /Library/Ruby/Gems/2.6.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:123:in `block in run'
     # /Library/Ruby/Gems/2.6.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:110:in `loop'
     # /Library/Ruby/Gems/2.6.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:110:in `run'
     # /Library/Ruby/Gems/2.6.0/gems/rspec-retry-0.6.1/lib/rspec_ext/rspec_ext.rb:12:in `run_with_retry'
     # /Library/Ruby/Gems/2.6.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:37:in `block (2 levels) in setup'

Finished in 0.00641 seconds (files took 1.27 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./test_spec.rb:6 # Restoring a backup Backups Should be able to backup an identical tar

You can see around the middle that the debug message gave us some helpful information:

Expected tmp/test_backup/world.txt to exist

Now we can tell which file is missing next time this error appears.

Checklist

See Definition of done.

For anything in this list which will not be completed, please provide a reason in the MR discussion.

Required

  • Merge Request Title and Description are up to date, accurate, and descriptive
  • MR targeting the appropriate branch
  • MR has a green pipeline on GitLab.com

Expected (please provide an explanation if not completing)

  • Test plan indicating conditions for success has been posted and passes
  • Documentation created/updated
  • Tests added
  • Integration tests added to GitLab QA
  • Equivalent MR/issue for omnibus-gitlab opened

Closes #2942 (closed)

Edited by Mitchell Nielsen

Merge request reports