<commit_before>require 'spec_helper'

def mock_api_response(data = {})
  Hashie::Rash.new(data)
end

describe Chef::Knife::DigitalOceanDropletCreate do

  subject {
    s = Chef::Knife::DigitalOceanDropletCreate.new
    s.stub(:client).and_return mock(DigitalOcean::API)
    s
  }

  let(:config) {
    {
      :digital_ocean_client_id => 'CLIENT_ID',
      :digital_ocean_api_key   => 'API_KEY',
      :server_name => 'sever-name.example.com',
      :image       => 11111,
      :location    => 22222,
      :size        => 33333,
      :ssh_key_ids => [ 44444, 44445 ]
    }
  }

  let(:custom_config) {
    {}
  }

  let(:api_response) {
    {
      :status => 'OK',
      :droplet => { :id => '123' }
    }
  }

  before do
    Chef::Knife::DigitalOceanDropletCreate.load_deps

    # reset
    Chef::Config[:knife] = {}

    # config
    config.merge(custom_config).each do |k, v|
      Chef::Config[:knife][k] = v
    end
  end

  context 'bootstrapping for chef-server' do
    let(:custom_config) {
      {
       :bootstrap => true
      }
    }
<commit_msg>Tests fixed to work with mixlib-config >= 2 (backwards compatible)<commit_after>require 'spec_helper'

def mock_api_response(data = {})
  Hashie::Rash.new(data)
end

describe Chef::Knife::DigitalOceanDropletCreate do

  subject {
    s = Chef::Knife::DigitalOceanDropletCreate.new
    s.stub(:client).and_return mock(DigitalOcean::API)
    s
  }

  let(:config) {
    {
      :digital_ocean_client_id => 'CLIENT_ID',
      :digital_ocean_api_key   => 'API_KEY',
      :server_name => 'sever-name.example.com',
      :image       => 11111,
      :location    => 22222,
      :size        => 33333,
      :ssh_key_ids => [ 44444, 44445 ]
    }
  }

  let(:custom_config) {
    {}
  }

  let(:api_response) {
    {
      :status => 'OK',
      :droplet => { :id => '123' }
    }
  }

  before do
    Chef::Knife::DigitalOceanDropletCreate.load_deps

    # reset
    if Chef::Config[:knife].respond_to?(:reset)
      # mixlib-config >= 2
      Chef::Config[:knife].reset
    else
      # mixlib-config < 2
      Chef::Config[:knife] = {}
    end

    # config
    config.merge(custom_config).each do |k, v|
      Chef::Config[:knife][k] = v
    end
  end

  context 'bootstrapping for chef-server' do
    let(:custom_config) {
      {
       :bootstrap => true
      }
    }

{'fraction_non_alphanumeric': 0.1446917808219178, 'fraction_numerical': 0.025256849315068493, 'mean_word_length': 2.4776785714285716, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 27, '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': '824408', 'n_tokens_mistral': 934, 'n_tokens_neox': 846, 'n_words': 137}