|
| 1 | +import "mocha"; |
| 2 | +import { expect } from "chai"; |
| 3 | +import { setLocalhostConfig } from "../src/setLocalhostConfig"; |
| 4 | + |
| 5 | +describe("setLocalhostConfig", function () { |
| 6 | + it("sets localhost endpoint", function () { |
| 7 | + const remoteConfig = `[Interface] |
| 8 | +Address = AX032NVGI2RIB4 |
| 9 | +PrivateKey = HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw= |
| 10 | +DNS = 172.33.1.2 |
| 11 | +
|
| 12 | +[Peer] |
| 13 | +PublicKey = gI6EdUSYvn8ugXOt8QQD6Yc+JyiZxIhp3GInSWRfWGE= |
| 14 | +Endpoint = ff0239facf453517.dyndns.dappnode.io:51820 |
| 15 | +AllowedIPs = 0.0.0.0/0`; |
| 16 | + |
| 17 | + const expectedLocalhostConfig = `[Interface] |
| 18 | +Address = AX032NVGI2RIB4 |
| 19 | +PrivateKey = HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw= |
| 20 | +DNS = 172.33.1.2 |
| 21 | +
|
| 22 | +[Peer] |
| 23 | +PublicKey = gI6EdUSYvn8ugXOt8QQD6Yc+JyiZxIhp3GInSWRfWGE= |
| 24 | +Endpoint = localhost:51820 |
| 25 | +AllowedIPs = 0.0.0.0/0`; |
| 26 | + |
| 27 | + expect(setLocalhostConfig(remoteConfig)).to.deep.equal( |
| 28 | + expectedLocalhostConfig, |
| 29 | + ); |
| 30 | + }); |
| 31 | + |
| 32 | + it("replaces endpoint when spacing around equal sign varies", function () { |
| 33 | + const remoteConfig = `[Peer] |
| 34 | +Endpoint = ff0239facf453517.dyndns.dappnode.io:51820`; |
| 35 | + |
| 36 | + const expectedLocalhostConfig = `[Peer] |
| 37 | +Endpoint = localhost:51820`; |
| 38 | + |
| 39 | + expect(setLocalhostConfig(remoteConfig)).to.deep.equal( |
| 40 | + expectedLocalhostConfig, |
| 41 | + ); |
| 42 | + }); |
| 43 | +}); |
0 commit comments