-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathtypeahead.js
More file actions
77 lines (67 loc) · 2.49 KB
/
typeahead.js
File metadata and controls
77 lines (67 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
exports.setup = function (svc, loggedOutSvc) {
var assert = require('chai').assert;
return (
describe("Typeahead Tests", () => {
beforeEach(function () {
this.service = svc;
this.loggedOutService = loggedOutSvc;
})
it("Typeahead failure", async function () {
let service = this.loggedOutService;
let res;
try {
res = await service.typeahead("index=", 1);
} catch (err) {
assert.ok(err);
}
assert.ok(!res);
})
it("Typeahead basic", async function () {
let service = this.service;
let options = await service.typeahead("index=", 1);
assert.ok(options);
assert.strictEqual(options.length, 1);
assert.ok(options[0]);
})
it("Typeahead with omitted optional arguments", async function () {
let service = this.service;
let options = await service.typeahead("index=");
assert.ok(options);
})
})
);
};
if (module.id === __filename && module.parent.id.includes('mocha')) {
var splunkjs = require('../../index');
var options = require('../cmdline');
let cmdline = options.create().parse(process.argv);
// If there is no command line, we should return
if (!cmdline) {
throw new Error("Error in parsing command line parameters");
}
let svc = new splunkjs.Service({
scheme: cmdline.opts.scheme,
host: cmdline.opts.host,
port: cmdline.opts.port,
username: cmdline.opts.username,
password: cmdline.opts.password,
version: cmdline.opts.version
});
let loggedOutSvc = new splunkjs.Service({
scheme: cmdline.opts.scheme,
host: cmdline.opts.host,
port: cmdline.opts.port,
username: cmdline.opts.username,
password: cmdline.opts.password + 'wrong',
version: cmdline.opts.version
});
// Exports tests on a successful login
module.exports = new Promise(async (resolve, reject) => {
try {
await svc.login();
return resolve(exports.setup(svc,loggedOutSvc))
} catch (error) {
throw new Error("Login failed - not running tests", error || "");
}
});
}