1 | 'use strict'
|
2 |
|
3 | const test = require('tap').test
|
4 | const getLoggingPaths = require('@nearform/clinic-common').getLoggingPaths('doctor')
|
5 | const path = require('path')
|
6 |
|
7 | test('Collect - logging path - identifier', function (t) {
|
8 | const paths = getLoggingPaths({ identifier: 1062 })
|
9 |
|
10 | t.strictDeepEqual(paths, {
|
11 | '/': '1062.clinic-doctor',
|
12 | '/traceevent': path.join('1062.clinic-doctor', '1062.clinic-doctor-traceevent'),
|
13 | '/systeminfo': path.join('1062.clinic-doctor', '1062.clinic-doctor-systeminfo'),
|
14 | '/processstat': path.join('1062.clinic-doctor', '1062.clinic-doctor-processstat')
|
15 | })
|
16 | t.end()
|
17 | })
|
18 |
|
19 | test('Collect - logging path - path', function (t) {
|
20 | const paths = getLoggingPaths({ path: path.join('root', '1062.clinic-doctor') })
|
21 |
|
22 | t.strictDeepEqual(paths, {
|
23 | '/': path.join('root', '1062.clinic-doctor'),
|
24 | '/traceevent': path.join('root', '1062.clinic-doctor', '1062.clinic-doctor-traceevent'),
|
25 | '/systeminfo': path.join('root', '1062.clinic-doctor', '1062.clinic-doctor-systeminfo'),
|
26 | '/processstat': path.join('root', '1062.clinic-doctor', '1062.clinic-doctor-processstat')
|
27 | })
|
28 | t.end()
|
29 | })
|
30 |
|
31 | test('Collect - logging path - path and identifier', function (t) {
|
32 | const paths = getLoggingPaths({ path: './foo', identifier: 1062 })
|
33 |
|
34 | t.strictDeepEqual(paths, {
|
35 | '/': path.join('foo', '1062.clinic-doctor'),
|
36 | '/traceevent': path.join('foo', '1062.clinic-doctor', '1062.clinic-doctor-traceevent'),
|
37 | '/systeminfo': path.join('foo', '1062.clinic-doctor', '1062.clinic-doctor-systeminfo'),
|
38 | '/processstat': path.join('foo', '1062.clinic-doctor', '1062.clinic-doctor-processstat')
|
39 | })
|
40 | t.end()
|
41 | })
|
42 |
|
43 | test('Collect - logging path - null path and identifier', function (t) {
|
44 | const paths = getLoggingPaths({ path: null, identifier: 1062 })
|
45 |
|
46 | t.strictDeepEqual(paths, {
|
47 | '/': path.join('', '1062.clinic-doctor'),
|
48 | '/traceevent': path.join('', '1062.clinic-doctor', '1062.clinic-doctor-traceevent'),
|
49 | '/systeminfo': path.join('', '1062.clinic-doctor', '1062.clinic-doctor-systeminfo'),
|
50 | '/processstat': path.join('', '1062.clinic-doctor', '1062.clinic-doctor-processstat')
|
51 | })
|
52 | t.end()
|
53 | })
|
54 |
|
55 | test('Collect - logging testing null values', function (t) {
|
56 | t.throws(
|
57 | () => getLoggingPaths({ identifier: null }),
|
58 | new Error('missing either identifier or path value')
|
59 | )
|
60 | t.throws(
|
61 | () => getLoggingPaths({ path: null }),
|
62 | new Error('missing either identifier or path value')
|
63 | )
|
64 | t.throws(
|
65 | () => getLoggingPaths({ path: null, identifier: null }),
|
66 | new Error('missing either identifier or path value')
|
67 | )
|
68 | t.end()
|
69 | })
|
70 |
|
71 | test('Collect - logging path - bad type', function (t) {
|
72 | t.throws(
|
73 | () => getLoggingPaths({}),
|
74 | new Error('missing either identifier or path value')
|
75 | )
|
76 | t.end()
|
77 | })
|