<commit_before>/*!
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

'use strict';

var assert = require('assert');
var async = require('async');
var uuid = require('node-uuid');
var exec = require('methmeth');
var extend = require('extend');

var Table = require('../src/table.js');
var Family = require('../src/family.js');
var Row = require('../src/row.js');

var env = require('../../../system-test/env.js');
var Bigtable = require('../');

var clusterName = process.env.GCLOUD_TESTS_BIGTABLE_CLUSTER;
var zoneName = process.env.GCLOUD_TESTS_BIGTABLE_ZONE;

var isTestable = clusterName && zoneName;

function generateTableName() {
  return 'test-table-' + uuid.v4();
}

(isTestable ? describe : describe.skip)('Bigtable', function() {
  var bigtable = new Bigtable(extend({}, env, {
    cluster: clusterName,
    zone: zoneName
  }));

  var TABLE_NAME = generateTableName();
  var TABLE = bigtable.table(TABLE_NAME);

  before(function(done) {
    bigtable.getTables(function(err, tables) {
      if (err) {
        done(err);
        return;
      }

      async.each(tables, exec('delete'), function(err) {
        if (err) {
          done(err);
          return;
        }

        TABLE.create(done);
      });
    });
  });

  after(function() {
    TABLE.delete();
  });

  describe('tables', function() {

    it('should retrieve a list of tables', function(done) {
      bigtable.getTables(function(err, tables) {
        assert.ifError(err);
        assert(tables[0] instanceof Table);
        done();
      });
    });

    it('should check if a table exists', function(done) {
      TABLE.exists(function(err, exists) {
        assert.ifError(err);
        assert.strictEqual(exists, true);
        done();
      });
    });

    it('should check if a table does not exist', function(done) {
      var table = bigtable.table('should-not-exist');

      table.exists(function(err, exists) {
        assert.ifError(err);
        assert.strictEqual(exists, false);
        done();
      });
    });

    it('should get a table', function(done) {
      var table = bigtable.table(TABLE_NAME);

      table.get(function(err, table_) {
        assert.ifError(err);
        assert.strictEqual(table, table_);
        done();
      });
    });

    it('should delete a table', function(done) {
      var table = bigtable.table(generateTableName());

      async.series([
        table.create.bind(table),
        table.delete.bind(table)
      ], done);
    });

    it('should get the tables metadata', function(done) {
      TABLE.getMetadata(function(err, metadata) {
        assert.strictEqual(metadata.name, TABLE.id);
        done();
      });
    });

  });

  describe('column families', function() {
    var FAMILY_NAME = 'presidents';
    var FAMILY = TABLE.family(FAMILY_NAME);

    before(function(done) {
      FAMILY.create(done);
    });

    it('should get a list of families', function(done) {
      TABLE.getFamilies(function(err, families) {
        assert.ifError(err);
        assert.strictEqual(families.length, 1);
        assert(families[0] instanceof Family);
        assert.strictEqual(families[0].name, FAMILY.name);
        done();
      });
    });

    it('should get a family', function(done) {
      var family = TABLE.family(FAMILY_NAME);

      family.get(function(err, family) {
        assert.ifError(err);
        assert(family instanceof Family);
        assert.strictEqual(family.name, FAMILY.name);
        done();
      });<commit_msg>bigtable: system tests (#1461)<commit_after>/*!
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

'use strict';

var assert = require('assert');
var async = require('async');
var exec = require('methmeth');
var extend = require('extend');
var uuid = require('node-uuid');

var Table = require('../src/table.js');
var Family = require('../src/family.js');
var Row = require('../src/row.js');

var env = require('../../../system-test/env.js');
var Bigtable = require('../');

var clusterName = process.env.GCLOUD_TESTS_BIGTABLE_CLUSTER;
var zoneName = process.env.GCLOUD_TESTS_BIGTABLE_ZONE;

var isTestable = clusterName && zoneName;

function generateTableName() {
  return 'test-table-' + uuid.v4();
}

(isTestable ? describe : describe.skip)('Bigtable', function() {
  var bigtable;

  var TABLE_NAME = generateTableName();
  var TABLE;

  before(function(done) {
    bigtable = new Bigtable(extend({
      cluster: clusterName,
      zone: zoneName
    }, env));

    TABLE = bigtable.table(TABLE_NAME);

    bigtable.getTables(function(err, tables) {
      if (err) {
        done(err);
        return;
      }

      async.each(tables, exec('delete'), function(err) {
        if (err) {
          done(err);
          return;
        }

        TABLE.create(done);
      });
    });
  });

  after(function() {
    TABLE.delete();
  });

  describe('tables', function() {

    it('should retrieve a list of tables', function(done) {
      bigtable.getTables(function(err, tables) {
        assert.ifError(err);
        assert(tables[0] instanceof Table);
        done();
      });
    });

    it('should check if a table exists', function(done) {
      TABLE.exists(function(err, exists) {
        assert.ifError(err);
        assert.strictEqual(exists, true);
        done();
      });
    });

    it('should check if a table does not exist', function(done) {
      var table = bigtable.table('should-not-exist');

      table.exists(function(err, exists) {
        assert.ifError(err);
        assert.strictEqual(exists, false);
        done();
      });
    });

    it('should get a table', function(done) {
      var table = bigtable.table(TABLE_NAME);

      table.get(function(err, table_) {
        assert.ifError(err);
        assert.strictEqual(table, table_);
        done();
      });
    });

    it('should delete a table', function(done) {
      var table = bigtable.table(generateTableName());

      async.series([
        table.create.bind(table),
        table.delete.bind(table)
      ], done);
    });

    it('should get the tables metadata', function(done) {
      TABLE.getMetadata(function(err, metadata) {
        assert.strictEqual(metadata.name, TABLE.id);
        done();
      });
    });

  });

  describe('column families', function() {
    var FAMILY_NAME = 'presidents';
    var FAMILY;

    before(function(done) {
      FAMILY = TABLE.family(FAMILY_NAME);
      FAMILY.create(done);
    });

    it('should get a list of families', function(done) {
      TABLE.getFamilies(function(err, families) {
        assert.ifError(err);
        assert.strictEqual(families.length, 1);
        assert(families[0] instanceof Family);
        assert.strictEqual(families[0].name, FAMILY.name);
        done();
      });
    });

    it('should get a family', function(done) {
      var family = TABLE.family(FAMILY_NAME);

      family.get(function(err, family) {
        assert.ifError(err);
        assert(family instanceof Family);
        assert.strictEqual(family.name, FAMILY.name);
        done();
      });
{'fraction_non_alphanumeric': 0.14359225679980397, 'fraction_numerical': 0.0036755697133055622, 'mean_word_length': 2.772181146025878, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1170296', 'n_tokens_mistral': 2474, 'n_tokens_neox': 2379, 'n_words': 604}