<commit_before>const assert = require('assert');
const { GCP } = require('../../../../../../lib/data/external/GCP');
const { makeGcpRequest } = require('../../../utils/makeRequest');
const { gcpRequestRetry } = require('../../../utils/gcpUtils');
const { getRealAwsConfig } =
    require('../../../../aws-node-sdk/test/support/awsConfig');

const credentialOne = 'gcpbackend';
const bucketName = `somebucket-${Date.now()}`;

describe('GCP: PUT Object', function testSuite() {
    this.timeout(30000);
    const config = getRealAwsConfig(credentialOne);
    const gcpClient = new GCP(config);

    before(done => {
        gcpRequestRetry({
            method: 'PUT',
            bucket: bucketName,
            authCredentials: config.credentials,
        }, 0, err => {
            if (err) {
                process.stdout.write(`err in creating bucket ${err}\n`);
            }
            return done(err);
        });
    });

    after(done => {
        gcpRequestRetry({
            method: 'DELETE',
            bucket: bucketName,
            authCredentials: config.credentials,
        }, 0, err => {
            if (err) {
                process.stdout.write(`err in deleting bucket ${err}\n`);
            }
            return done(err);
        });
    });

    afterEach(function afterFn(done) {
        makeGcpRequest({
            method: 'DELETE',
            bucket: bucketName,
            objectKey: this.currentTest.key,
            authCredentials: config.credentials,
        }, err => {
            if (err) {
                process.stdout.write(`err in deleting object ${err}\n`);
            }
            return done(err);
        });
    });

    describe('with existing object in bucket', () => {
        beforeEach(function beforeFn(done) {
            this.currentTest.key = `somekey-${Date.now()}`;
            gcpRequestRetry({
                method: 'PUT',
                bucket: this.currentTest.bucketName,
                objectKey: this.currentTest.key,
                authCredentials: config.credentials,
            }, 0, (err, res) => {
                if (err) {
                    process.stdout.write(`err in putting object ${err}\n`);
                    return done(err);
                }
                this.currentTest.uploadId =
                    res.headers['x-goog-generation'];
                return done();
            });
        });

        it('should overwrite object', function testFn(done) {
            gcpClient.putObject({
                Bucket: bucketName,
                Key: this.test.key,
            }, (err, res) => {
                assert.notStrictEqual(res.VersionId, this.test.uploadId);
                return done();
            });
        });
    });
<commit_msg>FX: GCP PUT API Test<commit_after>const assert = require('assert');
const { GCP } = require('../../../../../../lib/data/external/GCP');
const { makeGcpRequest } = require('../../../utils/makeRequest');
const { gcpRequestRetry } = require('../../../utils/gcpUtils');
const { getRealAwsConfig } =
    require('../../../../aws-node-sdk/test/support/awsConfig');

const credentialOne = 'gcpbackend';
const bucketName = `somebucket-${Date.now()}`;

describe('GCP: PUT Object', function testSuite() {
    this.timeout(30000);
    const config = getRealAwsConfig(credentialOne);
    const gcpClient = new GCP(config);

    before(done => {
        gcpRequestRetry({
            method: 'PUT',
            bucket: bucketName,
            authCredentials: config.credentials,
        }, 0, err => {
            if (err) {
                process.stdout.write(`err in creating bucket ${err}\n`);
            }
            return done(err);
        });
    });

    after(done => {
        gcpRequestRetry({
            method: 'DELETE',
            bucket: bucketName,
            authCredentials: config.credentials,
        }, 0, err => {
            if (err) {
                process.stdout.write(`err in deleting bucket ${err}\n`);
            }
            return done(err);
        });
    });

    afterEach(function afterFn(done) {
        makeGcpRequest({
            method: 'DELETE',
            bucket: bucketName,
            objectKey: this.currentTest.key,
            authCredentials: config.credentials,
        }, err => {
            if (err) {
                process.stdout.write(`err in deleting object ${err}\n`);
            }
            return done(err);
        });
    });

    describe('with existing object in bucket', () => {
        beforeEach(function beforeFn(done) {
            this.currentTest.key = `somekey-${Date.now()}`;
            gcpRequestRetry({
                method: 'PUT',
                bucket: bucketName,
                objectKey: this.currentTest.key,
                authCredentials: config.credentials,
            }, 0, (err, res) => {
                if (err) {
                    process.stdout.write(`err in putting object ${err}\n`);
                    return done(err);
                }
                this.currentTest.uploadId =
                    res.headers['x-goog-generation'];
                return done();
            });
        });

        it('should overwrite object', function testFn(done) {
            gcpClient.putObject({
                Bucket: bucketName,
                Key: this.test.key,
            }, (err, res) => {
                assert.notStrictEqual(res.VersionId, this.test.uploadId);
                return done();
            });
        });
    });

{'fraction_non_alphanumeric': 0.14756186317321687, 'fraction_numerical': 0.002911208151382824, 'mean_word_length': 1.5484469170143718, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '3624808', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1460, 'n_words': 290}