'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var chai_js = require('aegir/utils/chai.js');
var mocha = require('../utils/mocha.js');

function testDns(factory, options) {
  const describe = mocha.getDescribe(options);
  const it = mocha.getIt(options);
  describe('.dns', function () {
    this.timeout(60 * 1000);
    this.retries(3);
    let ipfs;
    before(async () => {
      ipfs = (await factory.spawn()).api;
    });
    after(() => factory.clean());
    it('should non-recursively resolve ipfs.io', async function () {
      try {
        const res = await ipfs.dns('ipfs.io', { recursive: false });
        chai_js.expect(res).to.match(/\/ipns\/.+$/);
      } catch (err) {
        if (err.message.includes('could not resolve name')) {
          return this.skip();
        }
        throw err;
      }
    });
    it('should recursively resolve ipfs.io', async function () {
      try {
        const res = await ipfs.dns('ipfs.io', { recursive: true });
        chai_js.expect(res).to.match(/\/ipfs\/.+$/);
      } catch (err) {
        if (err.message.includes('could not resolve name')) {
          return this.skip();
        }
        throw err;
      }
    });
    it('should resolve subdomain docs.ipfs.io', async function () {
      try {
        const res = await ipfs.dns('docs.ipfs.io');
        chai_js.expect(res).to.match(/\/ipfs\/.+$/);
      } catch (err) {
        if (err.message.includes('could not resolve name')) {
          return this.skip();
        }
        throw err;
      }
    });
  });
}

exports.testDns = testDns;
