<commit_before>'use strict';

import chai from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import S3FS from 's3fs';
import {FS} from '../lib/FS';
import {UnknownFolderException} from '../lib/Exception/UnknownFolderException';
import Kernel from 'deep-kernel';
import Log from 'deep-log';
import KernelFactory from './common/KernelFactory';
import OS from 'os';
import Path from 'path';
import nodeFS from 'fs';

chai.use(sinonChai);

suite('FS', () => {
  let fs = null;
  let backendKernelInstance = null;
  let path = 'hello.world.example/';

  test('Class FS exists in FS', () => {
    chai.expect(FS).to.be.an('function');
  });

  test('Load instance of FS by using Kernel.load()', (done) => {
    let callback = (backendKernel) => {
      backendKernelInstance = backendKernel;
      fs = backendKernel.get('fs');

      chai.assert.instanceOf(
        backendKernel, Kernel, 'backendKernel is an instance of Kernel'
      );
      chai.assert.instanceOf(
        fs, FS, 'fs is an instance of FS'
      );

      // complete the async
      done();
    };

    KernelFactory.create({
      FS: FS,
      Log: Log,
    }, callback);
  });

  test('Check TMP static getter returns "temp"', () => {
    chai.expect(FS.TMP).to.be.equal('temp');
  });

  test('Check PUBLIC static getter returns "public"', () => {
    chai.expect(FS.PUBLIC).to.be.equal('public');
  });

  test('Check SYSTEM static getter returns "system"', () => {
    chai.expect(FS.SYSTEM).to.be.equal('system');
  });

  test('Check SHARED static getter returns "shared"', () => {
    chai.expect(FS.SHARED).to.be.equal('shared');
  });

  test('Check FOLDERS static getter returns array of levels', () => {
    chai.expect(FS.FOLDERS.length).to.be.equal(4);
    chai.expect(FS.FOLDERS).to.be.include(FS.TMP);
    chai.expect(FS.FOLDERS).to.be.include(FS.PUBLIC);
    chai.expect(FS.FOLDERS).to.be.include(FS.SYSTEM);
    chai.expect(FS.FOLDERS).to.be.include(FS.SHARED);
  });

  test('Check boot() method boots a certain service', () => {
    let spyCallback = sinon.spy();

    fs.boot(backendKernelInstance, spyCallback);

    chai.expect(Object.keys(fs._buckets)).to.eql(['temp', 'public', 'system', 'shared']);
    chai.expect(spyCallback).to.have.been.calledWithExactly();
  });

  test('Check tmp() getter returns valid mounted tmp folder', () => {
    let bucketName = 'deep.dev.system.32f3705a';
    let actualResult = fs.tmp;

    chai.assert.instanceOf(actualResult, S3FS, 'result is an instance of S3FS');
    chai.expect(actualResult.bucket).to.equal(bucketName);
    chai.expect(actualResult.path).to.equal(`temp/${path}`);
  });

  test('Check public() getter returns valid mounted public folder', () => {
    let bucketName = 'deep.dev.public.32f3705a';

    let actualResult = fs.public;

    chai.assert.instanceOf(actualResult, S3FS, 'result is an instance of S3FS');
    chai.expect(actualResult.bucket).to.equal(bucketName);
    chai.expect(actualResult.path).to.equal(path);
  });

  test('Check system() getter returns valid mounted system folder', () => {
    let bucketName = 'deep.dev.system.32f3705a';
    let actualResult = fs.system;

    chai.assert.instanceOf(actualResult, S3FS, 'result is an instance of S3FS');
    chai.expect(actualResult.bucket).to.equal(bucketName);
    chai.expect(actualResult.path).to.equal(`system/${path}`);
  });

  test('Check getFolder() throws "UnknownFolderException" for invalid path',
    () => {
      let error = null;<commit_msg>Add tests<commit_after>'use strict';

import chai from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import S3FS from 's3fs';
import {FS} from '../lib/FS';
import {UnknownFolderException} from '../lib/Exception/UnknownFolderException';
import Kernel from 'deep-kernel';
import Log from 'deep-log';
import KernelFactory from './common/KernelFactory';
import OS from 'os';
import Path from 'path';
import nodeFS from 'fs';

chai.use(sinonChai);

suite('FS', () => {
  let fs = null;
  let backendKernelInstance = null;
  let path = 'hello.world.example/';

  test('Class FS exists in FS', () => {
    chai.expect(FS).to.be.an('function');
  });

  test('Load instance of FS by using Kernel.load()', (done) => {
    let callback = (backendKernel) => {
      backendKernelInstance = backendKernel;
      fs = backendKernel.get('fs');

      chai.assert.instanceOf(
        backendKernel, Kernel, 'backendKernel is an instance of Kernel'
      );
      chai.assert.instanceOf(
        fs, FS, 'fs is an instance of FS'
      );

      // complete the async
      done();
    };

    KernelFactory.create({
      FS: FS,
      Log: Log,
    }, callback);
  });

  test('Check TMP static getter returns "temp"', () => {
    chai.expect(FS.TMP).to.be.equal('temp');
  });

  test('Check PUBLIC static getter returns "public"', () => {
    chai.expect(FS.PUBLIC).to.be.equal('public');
  });

  test('Check SYSTEM static getter returns "system"', () => {
    chai.expect(FS.SYSTEM).to.be.equal('system');
  });

  test('Check SHARED static getter returns "shared"', () => {
    chai.expect(FS.SHARED).to.be.equal('shared');
  });

  test('Check FOLDERS static getter returns array of levels', () => {
    chai.expect(FS.FOLDERS.length).to.be.equal(4);
    chai.expect(FS.FOLDERS).to.be.include(FS.TMP);
    chai.expect(FS.FOLDERS).to.be.include(FS.PUBLIC);
    chai.expect(FS.FOLDERS).to.be.include(FS.SYSTEM);
    chai.expect(FS.FOLDERS).to.be.include(FS.SHARED);
  });

  test('Check boot() method boots a certain service', () => {
    let spyCallback = sinon.spy();

    fs.boot(backendKernelInstance, spyCallback);

    chai.expect(Object.keys(fs._buckets)).to.eql(['temp', 'public', 'system', 'shared']);
    chai.expect(spyCallback).to.have.been.calledWithExactly();
  });

  test('Check shared() getter returns valid mounted shared folder', () => {
    let bucketName = 'deep.dev.system.32f3705a';
    let actualResult = fs.shared();

    chai.assert.instanceOf(actualResult, S3FS, 'result is an instance of S3FS');
    chai.expect(actualResult.bucket).to.equal(bucketName);
    chai.expect(actualResult.path).to.equal(`shared/${path}`);
  });

  test('Check tmp() getter returns valid mounted tmp folder', () => {
    let bucketName = 'deep.dev.system.32f3705a';
    let actualResult = fs.tmp;

    chai.assert.instanceOf(actualResult, S3FS, 'result is an instance of S3FS');
    chai.expect(actualResult.bucket).to.equal(bucketName);
    chai.expect(actualResult.path).to.equal(`temp/${path}`);
  });

  test('Check public() getter returns valid mounted public folder', () => {
    let bucketName = 'deep.dev.public.32f3705a';

    let actualResult = fs.public;

    chai.assert.instanceOf(actualResult, S3FS, 'result is an instance of S3FS');
    chai.expect(actualResult.bucket).to.equal(bucketName);
    chai.expect(actualResult.path).to.equal(path);
  });

  test('Check system() getter returns valid mounted system folder', () => {
    let bucketName = 'deep.dev.system.32f3705a';
    let actualResult = fs.system;

    chai.assert.instanceOf(actualResult, S3FS, 'result is an instance of S3FS');
    chai.expect(actualResult.bucket).to.equal(bucketName);
    chai.expect(actualResult.path).to.equal(`system/${path}`);
  });

  test('Check getFolder() throws "UnknownFolderException" for invalid path',
    () => {
      let error = null;
{'fraction_non_alphanumeric': 0.16653094462540716, 'fraction_numerical': 0.008414766558089034, 'mean_word_length': 3.6787301587301586, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 32, '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': '4198946', 'n_tokens_mistral': 2508, 'n_tokens_neox': 2423, 'n_words': 524}