1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var path = require('path'),
|
9 | vows = require('vows'),
|
10 | nock = require('nock'),
|
11 | assert = require('assert'),
|
12 | helpers = require('./helpers');
|
13 |
|
14 | var options = {},
|
15 | testContext = {},
|
16 | config = helpers.loadConfig(),
|
17 | loggly = require('../lib/loggly').createClient(config);
|
18 |
|
19 | vows.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 | nock("https://" + config.subdomain + ".loggly.com", {
|
25 | reqheaders: {
|
26 | 'authorization': 'Basic ' + Buffer.from(config.auth.username + ":" + config.auth.password, 'base64')
|
27 | }
|
28 | })
|
29 | .get('/apiv2/search')
|
30 | .query({
|
31 | q: 'logging message'
|
32 | })
|
33 | .reply(200, {
|
34 | total_events: 1,
|
35 | page: 0,
|
36 | events: [{
|
37 | raw: 'this is a test logging message from /test/input-test.js',
|
38 | logtypes: [],
|
39 | timestamp: 1456830373968,
|
40 | unparsed: null,
|
41 | logmsg: 'this is a test logging message from /test/input-test.js',
|
42 | id: '9ce38479-df9d-11e5-802c-12a650209768',
|
43 | tags: [],
|
44 | event: {}
|
45 | }, ],
|
46 | callback: '',
|
47 | rsid: {
|
48 | status: 'SCHEDULED',
|
49 | date_from: 1455971607000,
|
50 | elapsed_time: 0.026120901107788086,
|
51 | date_to: 1456835607000,
|
52 | id: '897886661'
|
53 | }
|
54 |
|
55 | });
|
56 | nock("https://" + config.subdomain + ".loggly.com", {
|
57 | reqheaders: {
|
58 | 'authorization': 'Basic ' + Buffer.from(config.auth.username + ":" + config.auth.password, 'base64')
|
59 | }
|
60 | })
|
61 | .get('/apiv2/events')
|
62 | .query({
|
63 | rsid: '897886661'
|
64 | })
|
65 | .reply(200, {
|
66 | total_events: 1,
|
67 | page: 0,
|
68 | events: [{
|
69 | raw: 'this is a test logging message from /test/input-test.js',
|
70 | logtypes: [],
|
71 | timestamp: 1456830373968,
|
72 | unparsed: null,
|
73 | logmsg: 'this is a test logging message from /test/input-test.js',
|
74 | id: '9ce38479-df9d-11e5-802c-12a650209768',
|
75 | tags: [],
|
76 | event: {}
|
77 | }, ],
|
78 | callback: '',
|
79 | rsid: {
|
80 | status: 'SCHEDULED',
|
81 | date_from: 1455971607000,
|
82 | elapsed_time: 0.026120901107788086,
|
83 | date_to: 1456835607000,
|
84 | id: '897886661'
|
85 | }
|
86 |
|
87 | });
|
88 | loggly.search('logging message', this.callback)
|
89 | },
|
90 | "should return a set of valid search results": function(err, results) {
|
91 | helpers.assertSearch(err, results);
|
92 | }
|
93 | },
|
94 | "when searching with chaining": {
|
95 | topic: function() {
|
96 | nock("https://" + config.subdomain + ".loggly.com", {
|
97 | reqheaders: {
|
98 | 'authorization': 'Basic ' + Buffer.from(config.auth.username + ":" + config.auth.password, 'base64')
|
99 | }
|
100 | })
|
101 | .get('/apiv2/search')
|
102 | .query({
|
103 | q: 'logging message',
|
104 | callback: ''
|
105 | })
|
106 | .reply(200, {
|
107 | total_events: 1,
|
108 | page: 0,
|
109 | events: [{
|
110 | raw: 'this is a test logging message from /test/input-test.js',
|
111 | logtypes: [],
|
112 | timestamp: 1456830373968,
|
113 | unparsed: null,
|
114 | logmsg: 'this is a test logging message from /test/input-test.js',
|
115 | id: '9ce38479-df9d-11e5-802c-12a650209768',
|
116 | tags: [],
|
117 | event: {}
|
118 | }],
|
119 | callback: '',
|
120 | rsid: {
|
121 | status: 'SCHEDULED',
|
122 | date_from: 1455971607000,
|
123 | elapsed_time: 0.026120901107788086,
|
124 | date_to: 1456835607000,
|
125 | id: '897886661'
|
126 | }
|
127 | });
|
128 | nock("https://" + config.subdomain + ".loggly.com", {
|
129 | reqheaders: {
|
130 | 'authorization': 'Basic ' + Buffer(config.auth.username + ":" + config.auth.password, 'base64')
|
131 | }
|
132 | }).get('/apiv2/events')
|
133 | .query({
|
134 | rsid: '897886661'
|
135 | })
|
136 | .reply(200, {
|
137 | total_events: 1,
|
138 | page: 0,
|
139 | events: [{
|
140 | raw: 'this is a test logging message from /test/input-test.js',
|
141 | logtypes: [],
|
142 | timestamp: 1456830373968,
|
143 | unparsed: null,
|
144 | logmsg: 'this is a test logging message from /test/input-test.js',
|
145 | id: '9ce38479-df9d-11e5-802c-12a650209768',
|
146 | tags: [],
|
147 | event: {}
|
148 | }],
|
149 | callback: '',
|
150 | rsid: {
|
151 | status: 'SCHEDULED',
|
152 | date_from: 1455971607000,
|
153 | elapsed_time: 0.026120901107788086,
|
154 | date_to: 1456835607000,
|
155 | id: ''
|
156 | }
|
157 | });
|
158 | loggly.search('logging message')
|
159 | .run(this.callback);
|
160 | },
|
161 | "should return a set of valid search results": function(err, results) {
|
162 | helpers.assertSearch(err, results);
|
163 | }
|
164 | }
|
165 | },
|
166 | "the _checkRange() method": {
|
167 | "with invalid options set": {
|
168 | "should correct them": function() {
|
169 | var search = loggly.search({
|
170 | query: 'invalid logging message',
|
171 | from: 'now',
|
172 | until: '-1d'
|
173 | })
|
174 | ._checkRange();
|
175 |
|
176 | assert.equal(search.options.from, 'now');
|
177 | assert.equal(search.options.until, '-1d');
|
178 | }
|
179 | },
|
180 | "with valid options set": {
|
181 | "should not modify them": function() {
|
182 | var search = loggly.search({
|
183 | query: 'valid logging message',
|
184 | from: '-2M',
|
185 | until: 'now'
|
186 | })
|
187 | ._checkRange();
|
188 |
|
189 | assert.equal(search.options.from, '-2M');
|
190 | assert.equal(search.options.until, 'now');
|
191 | }
|
192 | }
|
193 | }
|
194 | }
|
195 | }).export(module);
|