Sha256: 2132ce6d3127eb2596064d3d86f567140dd0db2b1b7c9cbf974c7f209923580e

Contents?: true

Size: 1.22 KB

Versions: 7

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require 'open3'
require 'timeout'

describe 'bin/datadog_backup' do # rubocop:disable RSpec/DescribeClass
  # Contract Or[nil,String] => self
  def run_bin(env = {}, args = '')
    status = nil
    output = ''
    cmd = "bin/datadog_backup #{args}"
    Open3.popen2e(env, cmd) do |_i, oe, t|
      pid = t.pid

      Timeout.timeout(4.0) do
        oe.each do |v|
          output += v
        end
      end
    rescue Timeout::Error
      LOGGER.error "Timing out #{t.inspect} after 4 second"
      Process.kill(15, pid)
    ensure
      status = t.value
    end
    [output, status]
  end

  required_vars = %w[
    DD_API_KEY
    DD_APP_KEY
  ]

  env = {}
  required_vars.each do |v|
    env[v] = v.downcase
  end

  required_vars.map do |v|
    it "dies unless given ENV[#{v}]" do
      myenv = env.dup.tap { |h| h.delete(v) }
      _, status = run_bin(myenv, 'backup')
      expect(status).not_to be_success
    end
  end

  describe 'help' do
    subject(:bin) { run_bin(env, '--help') }

    it 'prints usage' do
      out_err, _status = bin
      expect(out_err).to match(/Usage: DD_API_KEY=/)
    end

    it 'exits cleanly' do
      _out_err, status = bin
      expect(status).to be_success
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
datadog_backup-4.0.1 spec/datadog_backup_bin_spec.rb
datadog_backup-4.0.0 spec/datadog_backup_bin_spec.rb
datadog_backup-3.3.0 spec/datadog_backup_bin_spec.rb
datadog_backup-3.2.1 spec/datadog_backup_bin_spec.rb
datadog_backup-3.2.0 spec/datadog_backup_bin_spec.rb
datadog_backup-3.1.1 spec/datadog_backup_bin_spec.rb
datadog_backup-3.1.0 spec/datadog_backup_bin_spec.rb