|
| 1 | +import { suite, test, suiteSetup, suiteTeardown } from "mocha"; |
| 2 | +import * as assert from "assert"; |
| 3 | +import * as os from "os"; |
| 4 | +import * as process from "process"; |
| 5 | +import { expandUser } from "../src-ts/utils"; |
| 6 | + |
| 7 | +suite("expandUser Test", function () { |
| 8 | + let home_env: { [key: string]: string | undefined } = {}; |
| 9 | + const local_username = os.userInfo().username; |
| 10 | + |
| 11 | + suiteSetup(function () { |
| 12 | + if (os.platform() == "win32") { |
| 13 | + this.skip(); |
| 14 | + } |
| 15 | + home_env.HOME = process.env.HOME; |
| 16 | + process.env.HOME = "/home/buildbot"; |
| 17 | + }); |
| 18 | + |
| 19 | + suiteTeardown(function () { |
| 20 | + process.env.HOME = home_env.HOME; |
| 21 | + }); |
| 22 | + |
| 23 | + test("tilde ", function () { |
| 24 | + assert.equal(expandUser("~"), "/home/buildbot"); |
| 25 | + assert.equal(expandUser("~/"), "/home/buildbot/"); |
| 26 | + assert.equal(expandUser("~/worker"), "/home/buildbot/worker"); |
| 27 | + }); |
| 28 | + |
| 29 | + test("tilde with username", function () { |
| 30 | + assert.equal(expandUser(`~${local_username}`), "/home/buildbot"); |
| 31 | + assert.equal(expandUser(`~${local_username}/`), "/home/buildbot/"); |
| 32 | + assert.equal(expandUser(`~${local_username}/dev`), "/home/buildbot/dev"); |
| 33 | + |
| 34 | + // test unknown user |
| 35 | + assert.notEqual(expandUser("~not_a_user"), "/home/build/bot"); |
| 36 | + }); |
| 37 | + |
| 38 | + test("empty", function () { |
| 39 | + assert.equal(expandUser(""), ""); |
| 40 | + }); |
| 41 | + |
| 42 | + test("no tilde", function () { |
| 43 | + assert.equal(expandUser("/home/buildbot/worker"), "/home/buildbot/worker"); |
| 44 | + }); |
| 45 | +}); |
0 commit comments