UNPKG

2.59 kBJavaScriptView Raw
1/*
2 * input-test.js: Tests for Loggly input requests
3 *
4 * (C) 2010 Nodejitsu Inc.
5 * MIT LICENSE
6 *
7 */
8
9var path = require('path'),
10 vows = require('vows'),
11 assert = require('assert'),
12 helpers = require('./helpers');
13
14var options = {},
15 testContext = {},
16 config = helpers.loadConfig(),
17 loggly = require('../lib/loggly').createClient(config);
18
19vows.describe('node-loggly/search').addBatch({
20 "When using the node-loggly client": {
21 "the search() method": {
22 "when searching without chaining": {
23 topic: function () {
24 loggly.search('logging message', this.callback);
25 },
26 "should return a set of valid search results": function (err, results) {
27 helpers.assertSearch(err, results);
28 }
29 },
30 "when searching with chaining": {
31 topic: function () {
32 loggly.search('logging message')
33 .meta({ inputname: 'test' })
34 .run(this.callback);
35 },
36 "should return a set of valid search results": function (err, results) {
37 helpers.assertSearch(err, results);
38 }
39 }
40 },
41 "the facet() method": {
42 "when searching by ip": {
43 topic: function () {
44 loggly.facet('ip', 'test', this.callback);
45 },
46 "should return a set of valid search results": function (err, results) {
47 helpers.assertSearch(err, results);
48 }
49 },
50 "when using chained searches": {
51 topic: function () {
52 loggly.facet('ip', 'test')
53 .context({ from: 'NOW-1MONTH' })
54 .run(this.callback);
55 },
56 "should return a set of valid search results": function (err, results) {
57 helpers.assertSearch(err, results);
58 }
59 }
60 },
61 "the _checkRange() method": {
62 "with invalid options set": {
63 "should correct them": function () {
64 var search = loggly.search('logging message')
65 .context({ from: 'NOW', until: '1DAY' })
66 ._checkRange();
67
68 assert.equal(search._context.from, 'NOW-24HOURS');
69 assert.equal(search._context.until, 'NOW');
70 }
71 },
72 "with valid options set": {
73 "should not modify them": function () {
74 var search = loggly.search('logging message')
75 .context({ from: 'NOW-2MONTHS', until: 'NOW' })
76 ._checkRange();
77
78 assert.equal(search._context.from, 'NOW-2MONTHS');
79 assert.equal(search._context.until, 'NOW');
80 }
81 }
82 }
83 }
84}).export(module);
\No newline at end of file