aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/server/index.ts1
-rw-r--r--server/tests/api/server/no-client.ts3
-rw-r--r--server/tests/api/server/open-telemetry.ts95
-rw-r--r--server/tests/shared/checks.ts9
-rw-r--r--server/tests/shared/mock-servers/index.ts1
-rw-r--r--server/tests/shared/mock-servers/mock-http.ts23
6 files changed, 129 insertions, 3 deletions
diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts
index 45be107ce..78522c246 100644
--- a/server/tests/api/server/index.ts
+++ b/server/tests/api/server/index.ts
@@ -17,5 +17,6 @@ import './slow-follows'
17import './stats' 17import './stats'
18import './tracker' 18import './tracker'
19import './no-client' 19import './no-client'
20import './open-telemetry'
20import './plugins' 21import './plugins'
21import './proxy' 22import './proxy'
diff --git a/server/tests/api/server/no-client.ts b/server/tests/api/server/no-client.ts
index 913907788..193f6c987 100644
--- a/server/tests/api/server/no-client.ts
+++ b/server/tests/api/server/no-client.ts
@@ -1,7 +1,6 @@
1import 'mocha'
2import request from 'supertest' 1import request from 'supertest'
3import { cleanupTests, createSingleServer, PeerTubeServer } from '@shared/server-commands'
4import { HttpStatusCode } from '@shared/models' 2import { HttpStatusCode } from '@shared/models'
3import { cleanupTests, createSingleServer, PeerTubeServer } from '@shared/server-commands'
5 4
6describe('Start and stop server without web client routes', function () { 5describe('Start and stop server without web client routes', function () {
7 let server: PeerTubeServer 6 let server: PeerTubeServer
diff --git a/server/tests/api/server/open-telemetry.ts b/server/tests/api/server/open-telemetry.ts
new file mode 100644
index 000000000..20909429f
--- /dev/null
+++ b/server/tests/api/server/open-telemetry.ts
@@ -0,0 +1,95 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { expectLogContain, expectLogDoesNotContain, MockHTTP } from '@server/tests/shared'
5import { HttpStatusCode, VideoPrivacy } from '@shared/models'
6import { cleanupTests, createSingleServer, makeRawRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
7
8describe('Open Telemetry', function () {
9 let server: PeerTubeServer
10
11 describe('Metrics', function () {
12 const metricsUrl = 'http://localhost:9091/metrics'
13
14 it('Should not enable open telemetry metrics', async function () {
15 server = await createSingleServer(1)
16
17 let hasError = false
18 try {
19 await makeRawRequest(metricsUrl, HttpStatusCode.NOT_FOUND_404)
20 } catch (err) {
21 hasError = err.message.includes('ECONNREFUSED')
22 }
23
24 expect(hasError).to.be.true
25
26 await server.kill()
27 })
28
29 it('Should enable open telemetry metrics', async function () {
30 server = await createSingleServer(1, {
31 open_telemetry: {
32 metrics: {
33 enabled: true
34 }
35 }
36 })
37
38 const res = await makeRawRequest(metricsUrl, HttpStatusCode.OK_200)
39 expect(res.text).to.contain('peertube_job_queue_total')
40
41 await server.kill()
42 })
43 })
44
45 describe('Tracing', function () {
46 let mockHTTP: MockHTTP
47 let mockPort: number
48
49 before(async function () {
50 mockHTTP = new MockHTTP()
51 mockPort = await mockHTTP.initialize()
52 })
53
54 it('Should enable open telemetry tracing', async function () {
55 server = await createSingleServer(1)
56
57 await expectLogDoesNotContain(server, 'Registering Open Telemetry tracing')
58
59 await server.kill()
60 })
61
62 it('Should enable open telemetry metrics', async function () {
63 server = await createSingleServer(1, {
64 open_telemetry: {
65 tracing: {
66 enabled: true,
67 jaeger_exporter: {
68 endpoint: 'http://localhost:' + mockPort
69 }
70 }
71 }
72 })
73
74 await expectLogContain(server, 'Registering Open Telemetry tracing')
75 })
76
77 it('Should upload a video and correctly works', async function () {
78 await setAccessTokensToServers([ server ])
79
80 const { uuid } = await server.videos.quickUpload({ name: 'video', privacy: VideoPrivacy.PUBLIC })
81
82 const video = await server.videos.get({ id: uuid })
83
84 expect(video.name).to.equal('video')
85 })
86
87 after(async function () {
88 await mockHTTP.terminate()
89 })
90 })
91
92 after(async function () {
93 await cleanupTests([ server ])
94 })
95})
diff --git a/server/tests/shared/checks.ts b/server/tests/shared/checks.ts
index 33b917f31..55ebc6c3e 100644
--- a/server/tests/shared/checks.ts
+++ b/server/tests/shared/checks.ts
@@ -29,6 +29,12 @@ async function expectLogDoesNotContain (server: PeerTubeServer, str: string) {
29 expect(content.toString()).to.not.contain(str) 29 expect(content.toString()).to.not.contain(str)
30} 30}
31 31
32async function expectLogContain (server: PeerTubeServer, str: string) {
33 const content = await server.servers.getLogContent()
34
35 expect(content.toString()).to.contain(str)
36}
37
32async function testImage (url: string, imageName: string, imageHTTPPath: string, extension = '.jpg') { 38async function testImage (url: string, imageName: string, imageHTTPPath: string, extension = '.jpg') {
33 const res = await makeGetRequest({ 39 const res = await makeGetRequest({
34 url, 40 url,
@@ -99,5 +105,6 @@ export {
99 expectNotStartWith, 105 expectNotStartWith,
100 checkBadStartPagination, 106 checkBadStartPagination,
101 checkBadCountPagination, 107 checkBadCountPagination,
102 checkBadSortPagination 108 checkBadSortPagination,
109 expectLogContain
103} 110}
diff --git a/server/tests/shared/mock-servers/index.ts b/server/tests/shared/mock-servers/index.ts
index abf4a8203..1fa983116 100644
--- a/server/tests/shared/mock-servers/index.ts
+++ b/server/tests/shared/mock-servers/index.ts
@@ -1,5 +1,6 @@
1export * from './mock-429' 1export * from './mock-429'
2export * from './mock-email' 2export * from './mock-email'
3export * from './mock-http'
3export * from './mock-instances-index' 4export * from './mock-instances-index'
4export * from './mock-joinpeertube-versions' 5export * from './mock-joinpeertube-versions'
5export * from './mock-object-storage' 6export * from './mock-object-storage'
diff --git a/server/tests/shared/mock-servers/mock-http.ts b/server/tests/shared/mock-servers/mock-http.ts
new file mode 100644
index 000000000..b7a019e07
--- /dev/null
+++ b/server/tests/shared/mock-servers/mock-http.ts
@@ -0,0 +1,23 @@
1import express from 'express'
2import { Server } from 'http'
3import { getPort, randomListen, terminateServer } from './shared'
4
5export class MockHTTP {
6 private server: Server
7
8 async initialize () {
9 const app = express()
10
11 app.get('/*', (req: express.Request, res: express.Response, next: express.NextFunction) => {
12 return res.sendStatus(200)
13 })
14
15 this.server = await randomListen(app)
16
17 return getPort(this.server)
18 }
19
20 terminate () {
21 return terminateServer(this.server)
22 }
23}