import { expect } from 'aegir/utils/chai.js';
import {
  getDescribe,
  getIt
} from '../utils/mocha.js';
export function testDns(factory, options) {
  const describe = getDescribe(options);
  const it = 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 });
        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 });
        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');
        expect(res).to.match(/\/ipfs\/.+$/);
      } catch (err) {
        if (err.message.includes('could not resolve name')) {
          return this.skip();
        }
        throw err;
      }
    });
  });
}