X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fredundancy%2Fmanage-redundancy.ts;h=e193b968e3826056fbe6e3f86804108de0ec68b2;hb=89d241a79c262b9775c233b73cff080043ebb5e6;hp=4253124c8f1fbedb86efe8719fe6b8ea6bb471e1;hpb=4c1def5fd8e9f483238eb38e221f555e2e6bbf07;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/redundancy/manage-redundancy.ts b/server/tests/api/redundancy/manage-redundancy.ts index 4253124c8..e193b968e 100644 --- a/server/tests/api/redundancy/manage-redundancy.ts +++ b/server/tests/api/redundancy/manage-redundancy.ts @@ -1,21 +1,17 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getLocalIdByUUID, + RedundancyCommand, ServerInfo, setAccessTokensToServers, - uploadVideo, - uploadVideoAndGetId, - waitUntilLog -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { addVideoRedundancy, listVideoRedundancies, removeVideoRedundancy, updateRedundancy } from '@shared/extra-utils/server/redundancy' -import { VideoPrivacy, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models' + waitJobs +} from '@shared/extra-utils' +import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models' const expect = chai.expect @@ -27,6 +23,8 @@ describe('Test manage videos redundancy', function () { let video2Server2UUID: string let redundanciesToRemove: number[] = [] + let commands: RedundancyCommand[] + before(async function () { this.timeout(120000) @@ -55,35 +53,33 @@ describe('Test manage videos redundancy', function () { // Get the access tokens await setAccessTokensToServers(servers) + commands = servers.map(s => s.redundancy) + { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) - video1Server2UUID = res.body.video.uuid + const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } }) + video1Server2UUID = uuid } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2' }) - video2Server2UUID = res.body.video.uuid + const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 2 server 2' } }) + video2Server2UUID = uuid } await waitJobs(servers) // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true) + await commands[0].updateRedundancy({ host: servers[1].host, redundancyAllowed: true }) await waitJobs(servers) }) it('Should not have redundancies on server 3', async function () { for (const target of targets) { - const res = await listVideoRedundancies({ - url: servers[2].url, - accessToken: servers[2].accessToken, - target - }) + const body = await commands[2].listVideos({ target }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } }) @@ -91,31 +87,22 @@ describe('Test manage videos redundancy', function () { this.timeout(120000) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 10) + await servers[0].servers.waitUntilLog('Duplicated ', 10) await waitJobs(servers) - const res = await listVideoRedundancies({ - url: servers[1].url, - accessToken: servers[1].accessToken, - target: 'remote-videos' - }) + const body = await commands[1].listVideos({ target: 'remote-videos' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should have "my-videos" redundancies on server 2', async function () { this.timeout(120000) - const res = await listVideoRedundancies({ - url: servers[1].url, - accessToken: servers[1].accessToken, - target: 'my-videos' - }) - - expect(res.body.total).to.equal(2) + const body = await commands[1].listVideos({ target: 'my-videos' }) + expect(body.total).to.equal(2) - const videos = res.body.data as VideoRedundancy[] + const videos = body.data expect(videos).to.have.lengthOf(2) const videos1 = videos.find(v => v.uuid === video1Server2UUID) @@ -139,28 +126,19 @@ describe('Test manage videos redundancy', function () { }) it('Should not have "my-videos" redundancies on server 1', async function () { - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, - target: 'my-videos' - }) + const body = await commands[0].listVideos({ target: 'my-videos' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should have "remote-videos" redundancies on server 1', async function () { this.timeout(120000) - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, - target: 'remote-videos' - }) + const body = await commands[0].listVideos({ target: 'remote-videos' }) + expect(body.total).to.equal(2) - expect(res.body.total).to.equal(2) - - const videos = res.body.data as VideoRedundancy[] + const videos = body.data expect(videos).to.have.lengthOf(2) const videos1 = videos.find(v => v.uuid === video1Server2UUID) @@ -185,81 +163,67 @@ describe('Test manage videos redundancy', function () { it('Should correctly paginate and sort results', async function () { { - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, + const body = await commands[0].listVideos({ target: 'remote-videos', sort: 'name', start: 0, count: 2 }) - const videos = res.body.data + const videos = body.data expect(videos[0].name).to.equal('video 1 server 2') expect(videos[1].name).to.equal('video 2 server 2') } { - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, + const body = await commands[0].listVideos({ target: 'remote-videos', sort: '-name', start: 0, count: 2 }) - const videos = res.body.data + const videos = body.data expect(videos[0].name).to.equal('video 2 server 2') expect(videos[1].name).to.equal('video 1 server 2') } { - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, + const body = await commands[0].listVideos({ target: 'remote-videos', sort: '-name', start: 1, count: 1 }) - const videos = res.body.data - expect(videos[0].name).to.equal('video 1 server 2') + expect(body.data[0].name).to.equal('video 1 server 2') } }) it('Should manually add a redundancy and list it', async function () { this.timeout(120000) - const uuid = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid + const uuid = (await servers[1].videos.quickUpload({ name: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid await waitJobs(servers) - const videoId = await getLocalIdByUUID(servers[0].url, uuid) + const videoId = await servers[0].videos.getId({ uuid }) - await addVideoRedundancy({ - url: servers[0].url, - accessToken: servers[0].accessToken, - videoId - }) + await commands[0].addVideo({ videoId }) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 15) + await servers[0].servers.waitUntilLog('Duplicated ', 15) await waitJobs(servers) { - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, + const body = await commands[0].listVideos({ target: 'remote-videos', sort: '-name', start: 0, count: 5 }) - const videos = res.body.data - expect(videos[0].name).to.equal('video 3 server 2') + const video = body.data[0] - const video = videos[0] + expect(video.name).to.equal('video 3 server 2') expect(video.redundancies.files).to.have.lengthOf(4) expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) @@ -276,19 +240,15 @@ describe('Test manage videos redundancy', function () { } } - const res = await listVideoRedundancies({ - url: servers[1].url, - accessToken: servers[1].accessToken, + const body = await commands[1].listVideos({ target: 'my-videos', sort: '-name', start: 0, count: 5 }) - const videos = res.body.data - expect(videos[0].name).to.equal('video 3 server 2') - - const video = videos[0] + const video = body.data[0] + expect(video.name).to.equal('video 3 server 2') expect(video.redundancies.files).to.have.lengthOf(4) expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) @@ -307,64 +267,47 @@ describe('Test manage videos redundancy', function () { this.timeout(120000) for (const redundancyId of redundanciesToRemove) { - await removeVideoRedundancy({ - url: servers[0].url, - accessToken: servers[0].accessToken, - redundancyId - }) + await commands[0].removeVideo({ redundancyId }) } { - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, + const body = await commands[0].listVideos({ target: 'remote-videos', sort: '-name', start: 0, count: 5 }) - const videos = res.body.data - expect(videos).to.have.lengthOf(2) + const videos = body.data - expect(videos[0].name).to.equal('video 2 server 2') + expect(videos).to.have.lengthOf(2) - redundanciesToRemove = [] const video = videos[0] + expect(video.name).to.equal('video 2 server 2') expect(video.redundancies.files).to.have.lengthOf(4) expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists) - for (const r of redundancies) { - redundanciesToRemove.push(r.id) - } + redundanciesToRemove = redundancies.map(r => r.id) } }) it('Should remove another (auto) redundancy', async function () { - { - for (const redundancyId of redundanciesToRemove) { - await removeVideoRedundancy({ - url: servers[0].url, - accessToken: servers[0].accessToken, - redundancyId - }) - } + for (const redundancyId of redundanciesToRemove) { + await commands[0].removeVideo({ redundancyId }) + } - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, - target: 'remote-videos', - sort: '-name', - start: 0, - count: 5 - }) + const body = await commands[0].listVideos({ + target: 'remote-videos', + sort: '-name', + start: 0, + count: 5 + }) - const videos = res.body.data - expect(videos[0].name).to.equal('video 1 server 2') - expect(videos).to.have.lengthOf(1) - } + const videos = body.data + expect(videos).to.have.lengthOf(1) + expect(videos[0].name).to.equal('video 1 server 2') }) after(async function () {