<commit_before># frozen_string_literal: true
require 'tempfile'
require 'spec_helper'

describe 'Integration tests', :integration => true do

  before(:all) do
    @conn = Fog::Storage[:aliyun]
    Fog::Logger.debug('Initializing Aliyun CLI for integration test population...')
    system("aliyun configure set --language en --region #{@conn.aliyun_region_id} --access-key-id #{@conn.aliyun_accesskey_id} --access-key-secret #{@conn.aliyun_accesskey_secret}")
  end

  before(:each) do
    Fog::Logger.debug("Initializing oss bucket for tests: #{@conn.aliyun_oss_bucket}")
    system("aliyun oss rm --bucket oss://#{@conn.aliyun_oss_bucket} -r -f > /dev/null || exit 0")
    system("aliyun oss mb oss://#{@conn.aliyun_oss_bucket} > /dev/null")
  end

  it 'Should get all directories in bucket' do
    system("aliyun oss mkdir oss://#{@conn.aliyun_oss_bucket}/test_dir1 > /dev/null")
    system("aliyun oss mkdir oss://#{@conn.aliyun_oss_bucket}/test_dir2 > /dev/null")
    system("aliyun oss mkdir oss://#{@conn.aliyun_oss_bucket}/test_dir3 > /dev/null")
    expect(@conn.directories.all.length).to eq(3)
  end

  it 'Should get container in bucket' do
    system("aliyun oss mkdir oss://#{@conn.aliyun_oss_bucket}/test_dir > /dev/null")
    expect(@conn.get_container('').length).to eq(1)
  end

  it 'Should find test file in the root of bucket' do
    file = Tempfile.new('fog-upload-file')
    file.write("Hello World!")
    begin
      system("aliyun oss appendfromfile #{file.path} oss://#{@conn.aliyun_oss_bucket}/test_file > /dev/null")
      files = @conn.directories.get(@conn.aliyun_oss_bucket).files
      expect(files.length).to eq(1)
      expect(files.empty?).to eq(false)
      expect(files[0].key).to eq("test_file")
      expect(files.get("test_file").key).to eq("test_file")
    ensure
      file.close
      file.unlink
    end
  end

  it 'Should find 2 tests file in the root of bucket' do
    file = Tempfile.new('fog-upload-file')
    file.write("Hello World!")
    begin
      system("aliyun oss appendfromfile #{file.path} oss://#{@conn.aliyun_oss_bucket}/test_file1 > /dev/null")
      system("aliyun oss appendfromfile #{file.path} oss://#{@conn.aliyun_oss_bucket}/test_file2 > /dev/null")
      files = @conn.directories.get(@conn.aliyun_oss_bucket).files
      expect(files.length).to eq(2)
      expect(files.all.length).to eq(2)
      expect(files.empty?).to eq(false)
      expect(files[0].key).to eq("test_file1")
      expect(files[1].key).to eq("test_file2")
      expect(files.get("test_file1").key).to eq("test_file1")
      expect(files.get("test_file2").key).to eq("test_file2")
    ensure
      file.close
      file.unlink
    end
  end<commit_msg>improve integration test to support delete directory and file<commit_after># frozen_string_literal: true
require 'tempfile'
require 'spec_helper'

describe 'Integration tests', :integration => true do

  before(:all) do
    @conn = Fog::Storage[:aliyun]
    Fog::Logger.debug('Initializing Aliyun CLI for integration test population...')
    system("aliyun configure set --language en --region #{@conn.aliyun_region_id} --access-key-id #{@conn.aliyun_accesskey_id} --access-key-secret #{@conn.aliyun_accesskey_secret}")
  end

  before(:each) do
    Fog::Logger.debug("Initializing oss bucket for tests: #{@conn.aliyun_oss_bucket}")
    system("aliyun oss rm --bucket oss://#{@conn.aliyun_oss_bucket} -r -f > /dev/null || exit 0")
    system("aliyun oss mb oss://#{@conn.aliyun_oss_bucket} > /dev/null")
  end

  it 'Should get all directories in bucket' do
    system("aliyun oss mkdir oss://#{@conn.aliyun_oss_bucket}/test_dir1 > /dev/null")
    system("aliyun oss mkdir oss://#{@conn.aliyun_oss_bucket}/test_dir2 > /dev/null")
    system("aliyun oss mkdir oss://#{@conn.aliyun_oss_bucket}/test_dir3 > /dev/null")
    expect(@conn.directories.all.length).to eq(3)
  end

  it 'Should get container in bucket' do
    system("aliyun oss mkdir oss://#{@conn.aliyun_oss_bucket}/test_dir > /dev/null")
    expect(@conn.get_container('').length).to eq(1)
  end

  it 'Should delete 2 directories in bucket' do
    system("aliyun oss mkdir oss://#{@conn.aliyun_oss_bucket}/test_dir1 > /dev/null")
    system("aliyun oss mkdir oss://#{@conn.aliyun_oss_bucket}/test_dir2 > /dev/null")
    expect(@conn.directories.all.length).to eq(2)
    file = @conn.directories.get(@conn.aliyun_oss_bucket, prefix:'test_dir1').files[0]
    file.destroy
    expect(@conn.directories.all.length).to eq(1)
    file = @conn.directories.get(@conn.aliyun_oss_bucket, prefix:'test_dir').files[0]
    file.destroy
    expect(@conn.directories.all).to eq(nil)
  end

  it 'Should find test file in the root of bucket' do
    file = Tempfile.new('fog-upload-file')
    file.write("Hello World!")
    begin
      system("aliyun oss appendfromfile #{file.path} oss://#{@conn.aliyun_oss_bucket}/test_file > /dev/null")
      files = @conn.directories.get(@conn.aliyun_oss_bucket).files
      expect(files.length).to eq(1)
      expect(files.empty?).to eq(false)
      expect(files[0].key).to eq("test_file")
      expect(files.get("test_file").key).to eq("test_file")
    ensure
      file.close
      file.unlink
    end
  end

  it 'Should find 2 tests file in the root of bucket' do
    file = Tempfile.new('fog-upload-file')
    file.write("Hello World!")
    begin
      system("aliyun oss appendfromfile #{file.path} oss://#{@conn.aliyun_oss_bucket}/test_file1 > /dev/null")
      system("aliyun oss appendfromfile #{file.path} oss://#{@conn.aliyun_oss_bucket}/test_file2 > /dev/null")
      files = @conn.directories.get(@conn.aliyun_oss_bucket).files
      expect(files.length).to eq(2)
      expect(files.all.length).to eq(2)
      expect(files.empty?).to eq(false)
      expect(files[0].key).to eq("test_file1")
      expect(files[1].key).to eq("test_file2")
      expect(files.get("test_file1").key).to eq("test_file1")
      expect(files.get("test_file2").key).to eq("test_file2")
    ensure
      file.close
      file.unlink
    end
  end

  it 'Should delete 2 tests file in the root of bucket' do
    file = Tempfile.new('fog-upload-file')
    file.write("Hello World!")
    begin
      system("aliyun oss appendfromfile #{file.path} oss://#{@conn.aliyun_oss_bucket}/test_file1 > /dev/null")
      system("aliyun oss appendfromfile #{file.path} oss://#{@conn.aliyun_oss_bucket}/test_file2 > /dev/null")
      files = @conn.directories.get(@conn.aliyun_oss_bucket).files
      expect(files.length).to eq(2)
      expect(files.all.length).to eq(2)
      expect(files.empty?).to eq(false)
      files[0].destroy
      expect(@conn.directories.get(@conn.aliyun_oss_bucket).files.length).to eq(1)
      files[1].destroy
      expect(@conn.directories.get(@conn.aliyun_oss_bucket).files.length).to eq(0)
    ensure
      file.close
      file.unlink
    end
  end
{'fraction_non_alphanumeric': 0.15505124450951685, 'fraction_numerical': 0.008638360175695461, 'mean_word_length': 3.665983606557377, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2107263', 'n_tokens_mistral': 2458, 'n_tokens_neox': 2401, 'n_words': 464}