{"size": 5686, "ext": "js", "max_stars_repo_path": "test/src/linux/index.js", "max_stars_repo_name": "qzdio/node-fsfilesystem", "max_stars_repo_stars_event_min_datetime": "2018-03-04T19:51:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T00:46:25.000Z", "max_issues_repo_path": "test/src/linux/index.js", "max_issues_repo_name": "qzdio/node-fsfilesystem", "max_issues_repo_issues_event_min_datetime": "2018-03-19T00:11:09.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-01T13:42:59.000Z", "max_forks_repo_path": "test/src/linux/index.js", "max_forks_repo_name": "qzdio/node-fsfilesystem", "max_forks_repo_forks_event_min_datetime": "2018-05-04T16:57:35.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-23T07:29:05.000Z"}
{"max_stars_count": 17, "max_issues_count": 51, "max_forks_count": 3, "avg_line_length": 40.9064748201, "max_line_length": 95, "alphanum_fraction": 0.5349982413}
import os from 'os';
import fs from 'fs';
import path from 'path';
import { expect } from 'chai';
import child from 'child_process';
import linux from '../../../src/linux';
import { ENVIRONMENT, inferDevSize } from '../../../src';

// eqeqeq :: * -> * -> Bool
const eqeqeq = (x) => (y) => x === y;

// ifElse :: (a -> Bool), (a -> *), (a -> *) -> (a -> *)
const ifElse = function ifElse (f, g, h) {
  return (x) => f(x) ? g(x) : h(x);
};

describe('linux integration tests', function() {
  describe('native tests', ifElse(
    eqeqeq('linux'),
    () => function(){
      it('should properly parse the output of the filesystem command', function(done){
        this.timeout(5000);
        const input = child.execSync(linux.COMMAND, ENVIRONMENT).toString();
        const userFilter = () => true;
        const firstParse = linux.parser(userFilter)(input).devices;
        const devices = inferDevSize(firstParse);
        expect(devices).to.be.an('object');
        expect(Object.keys(devices).length).to.be.at.least(1);
        for(const k in devices){
          expect(devices[k].id).to.be.a('string');
          expect(devices[k].node).to.be.a('string');
          expect(devices[k].size).to.be.a('number').that.is.gte(0);
          expect(devices[k].volumes).to.be.an('array');
          devices[k].volumes.forEach((v) => {
            expect(typeof v.name === 'string' || v.name === null).to.be.true;
            expect(typeof v.description === 'string' || v.description === null).to.be.true;
            expect(v.mounted).to.be.a('boolean');
            expect(v.space).to.be.an('object').that.has.all.keys('total', 'available', 'used');
            expect(
              (
                v.space.total === null &&
                v.space.available === null &&
                v.space.used === null
              ) ||
              (
                typeof v.space.total === 'number' && v.space.total >= 0 &&
                typeof v.space.available === 'number' && v.space.available >= 0 &&
                typeof v.space.used === 'number' && v.space.used >= 0
              )
            ).to.be.true;
          });
        }
        done();
      });
    },
    () => function() {
      it('should not run native linux tests', (done) => done());
    }
  )(os.platform()));

  describe('non-native tests', function(){
    it('should properly parse the provided static input', function(done){
      const input = fs.readFileSync(path.resolve(__dirname, 'input.txt'), 'utf-8');
      const userFilter = () => true;
      const firstParse = linux.parser(userFilter)(input).devices;
      const devices = inferDevSize(firstParse);
      expect(devices).to.be.an('object');
      expect(Object.keys(devices).length).to.be.at.least(1);
      for(const k in devices){
        expect(devices[k].id).to.be.a('string');
        expect(devices[k].node).to.be.a('string');
        expect(devices[k].size).to.be.a('number').that.is.gte(0);
        expect(devices[k].volumes).to.be.an('array');
        devices[k].volumes.forEach((v) => {
          expect(typeof v.name === 'string' || v.name === null).to.be.true;
          expect(typeof v.description === 'string' || v.description === null).to.be.true;
          expect(v.mounted).to.be.a('boolean');
          expect(v.space).to.be.an('object').that.has.all.keys('total', 'available', 'used');
          expect(
            (
              v.space.total === null &&
              v.space.available === null &&
              v.space.used === null
            ) ||
            (
              typeof v.space.total === 'number' && v.space.total >= 0 &&
              typeof v.space.available === 'number' && v.space.available >= 0 &&
              typeof v.space.used === 'number' && v.space.used >= 0
            )
          ).to.be.true;
        });
      }
      done();
    });

    it('should properly parse the provided static input2', function(done){
      const input = fs.readFileSync(path.resolve(__dirname, 'input2.txt')).toString();
      const userFilter = () => true;
      const parseit = () => linux.parser(userFilter)(input);
      expect(parseit).to.not.throw();
      done();
    });

    it('should properly parse the provided static input3, and infer disk size', function(done){
      const input = fs.readFileSync(path.resolve(__dirname, 'input3.txt')).toString();
      const userFilter = () => true;
      const firstParse = linux.parser(userFilter)(input).devices;
      const devices = inferDevSize(firstParse);
      expect(devices).to.be.an('object');
      expect(Object.keys(devices).length).to.be.at.least(1);
      for(const k in devices){
        expect(devices[k].id).to.be.a('string');
        expect(devices[k].node).to.be.a('string');
        expect(devices[k].size).to.be.a('number').that.is.gte(0);
        expect(devices[k].volumes).to.be.an('array');
        devices[k].volumes.forEach((v) => {
          expect(typeof v.name === 'string' || v.name === null).to.be.true;
          expect(typeof v.description === 'string' || v.description === null).to.be.true;
          expect(v.mounted).to.be.a('boolean');
          expect(v.space).to.be.an('object').that.has.all.keys('total', 'available', 'used');
          expect(
            (
              v.space.total === null &&
              v.space.available === null &&
              v.space.used === null
            ) ||
            (
              typeof v.space.total === 'number' && v.space.total >= 0 &&
              typeof v.space.available === 'number' && v.space.available >= 0 &&
              typeof v.space.used === 'number' && v.space.used >= 0
            )
          ).to.be.true;
        });
      };
      done();
    });
  });
});
