Skip to content

Commit

Permalink
feat: allow a different default target via config
Browse files Browse the repository at this point in the history
  • Loading branch information
darlanalves committed Apr 21, 2023
1 parent 3475de8 commit 0f9973f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 58 deletions.
74 changes: 31 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@cloud-cli/typescript-config": "^1.0.0"
},
"dependencies": {
"@cloud-cli/cli": "^1.6.0",
"@cloud-cli/exec": "^1.0.4"
}
}
25 changes: 20 additions & 5 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { DNS } from './index';
import dns from './index';
import dns, { parseDNSLine } from './index';
import fs from 'fs';
import * as exec from '@cloud-cli/exec';
import { init } from '@cloud-cli/cli';

beforeEach(() => {
jest.spyOn(fs, 'writeFileSync').mockImplementation();
jest.spyOn(fs, 'readFileSync').mockImplementation(() => '');
});

describe('dns', () => {
it('should parse a DNS configuration line', () => {
const line = 'address=/foo/1.2.3.4';
const output = DNS.parse(line);
const output = parseDNSLine(line);

expect(output).toEqual({ target: '1.2.3.4', domain: 'foo' });
});

Expand All @@ -15,9 +21,9 @@ describe('dns', () => {
const buffer = `address=/test/1.2.3.4\naddress=/foo/5.6.7.8`;
jest.spyOn(fs, 'existsSync').mockImplementation(() => fileExists);
jest.spyOn(fs, 'readFileSync').mockImplementation(() => buffer);

expect(dns.list()).toEqual([]);

fileExists = true;
const list = dns.list();
expect(list).toEqual([
Expand Down Expand Up @@ -57,4 +63,13 @@ describe('dns', () => {
await expect(dns.reload()).rejects.toEqual(new Error('Failed to reload'));
});
});

describe('dns configuration', () => {
it('should configure the default target', () => {
dns[init]({ defaultTarget: '1.1.2.2' });
dns.add({ domain: 'bar' });

expect(fs.writeFileSync).toHaveBeenCalledWith(expect.any(String), 'address=/bar/1.1.2.2');
});
})
});
Loading

0 comments on commit 0f9973f

Please sign in to comment.