google cloud api | check dns | invalidate cdn cache | Search

This code uses the Mocha testing framework to test the addIP function, which adds an external IP to a project and bucket, with error handling and a 60-second timeout. The code also utilizes a custom importer module and built-in Node.js assert module for assertions.

Run example

npm run import -- "test check dns"

test check dns

var assert = require('assert');
var importer = require('../Core');
var addIP = importer.import("check dns");
var project = 'spahaha-ea443';
var bucketName = 'sheet-to-web.sheet-to-web.com';

describe('adding an external ip', () => {
    it('should add an ip', () => {
        return addIP(project, bucketName)
            .then(ip => {
                console.log(ip);
                assert(ip.length > 0, 'should have added an ip');
            })
    }).timeout(60000)
    
});

What the code could have been:

const { describe, it, expect } = require('jest');

const { importCore } = require('../Core');
const { check_dns } = importCore();
const project ='spahaha-ea443';
const bucketName ='sheet-to-web.sheet-to-web.com';

describe('adding an external IP', () => {
    it('should add an IP', async () => {
        const ip = await check_dns(project, bucketName);
        expect(ip).toHaveLength(1); // improved assertion
        console.log(ip);
    }).timeout(60000);
});

Code Breakdown

Dependencies

Test Suite