Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Framasoft
PeerTube
PeerTube
Commits
d1bfbdeb
Verified
Commit
d1bfbdeb
authored
Oct 22, 2021
by
Chocobozzz
Browse files
Random listen for mocked servers
parent
5480933b
Pipeline
#453314
passed with stage
in 12 minutes and 34 seconds
Changes
7
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
server/tests/api/object-storage/videos.ts
View file @
d1bfbdeb
...
...
@@ -182,7 +182,7 @@ function runTestSuite (options: {
})
it
(
'
Should upload a video and move it to the object storage without transcoding
'
,
async
function
()
{
this
.
timeout
(
2
0000
)
this
.
timeout
(
4
0000
)
const
{
uuid
}
=
await
servers
[
0
].
videos
.
quickUpload
({
name
:
'
video 1
'
})
uuidsToDelete
.
push
(
uuid
)
...
...
shared/extra-utils/mock-servers/mock-instances-index.ts
View file @
d1bfbdeb
import
express
from
'
express
'
import
{
Server
}
from
'
http
'
import
{
randomInt
}
from
'
@shared/core-utils
'
import
{
terminateServer
}
from
'
./utils
'
import
{
getPort
,
randomListen
,
terminateServer
}
from
'
./utils
'
export
class
MockInstancesIndex
{
private
server
:
Server
private
readonly
indexInstances
:
{
host
:
string
,
createdAt
:
string
}[]
=
[]
initialize
()
{
return
new
Promise
<
number
>
(
res
=>
{
const
app
=
express
()
async
initialize
()
{
const
app
=
express
()
app
.
use
(
'
/
'
,
(
req
:
express
.
Request
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
{
if
(
process
.
env
.
DEBUG
)
console
.
log
(
'
Receiving request on mocked server %s.
'
,
req
.
url
)
app
.
use
(
'
/
'
,
(
req
:
express
.
Request
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
{
if
(
process
.
env
.
DEBUG
)
console
.
log
(
'
Receiving request on mocked server %s.
'
,
req
.
url
)
return
next
()
})
app
.
get
(
'
/api/v1/instances/hosts
'
,
(
req
:
express
.
Request
,
res
:
express
.
Response
)
=>
{
const
since
=
req
.
query
.
since
return
next
()
})
const
filtered
=
this
.
indexInstances
.
filter
(
i
=>
{
if
(
!
since
)
re
turn
tru
e
app
.
get
(
'
/api/v1/instances/hosts
'
,
(
req
:
express
.
Request
,
res
:
express
.
Response
)
=>
{
const
since
=
re
q
.
query
.
sinc
e
return
i
.
createdAt
>
since
})
const
filtered
=
this
.
indexInstances
.
filter
(
i
=>
{
if
(
!
since
)
return
true
return
res
.
json
({
total
:
filtered
.
length
,
data
:
filtered
})
return
i
.
createdAt
>
since
})
const
port
=
42000
+
randomInt
(
1
,
1000
)
this
.
server
=
app
.
listen
(
port
,
()
=>
res
(
port
))
return
res
.
json
({
total
:
filtered
.
length
,
data
:
filtered
})
})
this
.
server
=
await
randomListen
(
app
)
return
getPort
(
this
.
server
)
}
addInstance
(
host
:
string
)
{
...
...
shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts
View file @
d1bfbdeb
import
express
from
'
express
'
import
{
randomInt
}
from
'
@shared/core-utils
'
import
{
Server
}
from
'
http
'
import
{
getPort
,
randomListen
}
from
'
./utils
'
export
class
MockJoinPeerTubeVersions
{
private
server
:
Server
private
latestVersion
:
string
initialize
()
{
return
new
Promise
<
number
>
(
res
=>
{
const
app
=
express
()
async
initialize
()
{
const
app
=
express
()
app
.
use
(
'
/
'
,
(
req
:
express
.
Request
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
{
if
(
process
.
env
.
DEBUG
)
console
.
log
(
'
Receiving request on mocked server %s.
'
,
req
.
url
)
app
.
use
(
'
/
'
,
(
req
:
express
.
Request
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
{
if
(
process
.
env
.
DEBUG
)
console
.
log
(
'
Receiving request on mocked server %s.
'
,
req
.
url
)
return
next
()
})
return
next
()
})
app
.
get
(
'
/versions.json
'
,
(
req
:
express
.
Request
,
res
:
express
.
Response
)
=>
{
return
res
.
json
({
peertube
:
{
latestVersion
:
this
.
latestVersion
}
})
app
.
get
(
'
/versions.json
'
,
(
req
:
express
.
Request
,
res
:
express
.
Response
)
=>
{
return
res
.
json
({
peertube
:
{
latestVersion
:
this
.
latestVersion
}
})
const
port
=
43000
+
randomInt
(
1
,
1000
)
app
.
listen
(
port
,
()
=>
res
(
port
))
})
this
.
server
=
await
randomListen
(
app
)
return
getPort
(
this
.
server
)
}
setLatestVersion
(
latestVersion
:
string
)
{
...
...
shared/extra-utils/mock-servers/mock-object-storage.ts
View file @
d1bfbdeb
...
...
@@ -2,39 +2,37 @@ import express from 'express'
import
got
,
{
RequestError
}
from
'
got
'
import
{
Server
}
from
'
http
'
import
{
pipeline
}
from
'
stream
'
import
{
randomInt
}
from
'
@shared/core-utils
'
import
{
ObjectStorageCommand
}
from
'
../server
'
import
{
terminateServer
}
from
'
./utils
'
import
{
getPort
,
randomListen
,
terminateServer
}
from
'
./utils
'
export
class
MockObjectStorage
{
private
server
:
Server
initialize
()
{
return
new
Promise
<
number
>
(
res
=>
{
const
app
=
express
()
async
initialize
()
{
const
app
=
express
()
app
.
get
(
'
/:bucketName/:path(*)
'
,
(
req
:
express
.
Request
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
{
const
url
=
`http://
${
req
.
params
.
bucketName
}
.
${
ObjectStorageCommand
.
getEndpointHost
()}
/
${
req
.
params
.
path
}
`
app
.
get
(
'
/:bucketName/:path(*)
'
,
(
req
:
express
.
Request
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
{
const
url
=
`http://
${
req
.
params
.
bucketName
}
.
${
ObjectStorageCommand
.
getEndpointHost
()}
/
${
req
.
params
.
path
}
`
if
(
process
.
env
.
DEBUG
)
{
console
.
log
(
'
Receiving request on mocked server %s.
'
,
req
.
url
)
console
.
log
(
'
Proxifying request to %s
'
,
url
)
}
return
pipeline
(
got
.
stream
(
url
,
{
throwHttpErrors
:
false
}),
res
,
(
err
:
RequestError
)
=>
{
if
(
!
err
)
return
if
(
process
.
env
.
DEBUG
)
{
console
.
log
(
'
Receiving request on mocked server %s.
'
,
req
.
url
)
console
.
log
(
'
Proxifying request to %s
'
,
url
)
}
console
.
error
(
'
Pipeline failed.
'
,
err
)
}
)
})
return
pipeline
(
got
.
stream
(
url
,
{
throwHttpErrors
:
false
}),
res
,
(
err
:
RequestError
)
=>
{
if
(
!
err
)
return
const
port
=
44000
+
randomInt
(
1
,
1000
)
this
.
server
=
app
.
listen
(
port
,
()
=>
res
(
port
))
console
.
error
(
'
Pipeline failed.
'
,
err
)
}
)
})
this
.
server
=
await
randomListen
(
app
)
return
getPort
(
this
.
server
)
}
terminate
()
{
...
...
shared/extra-utils/mock-servers/mock-plugin-blocklist.ts
View file @
d1bfbdeb
import
express
,
{
Request
,
Response
}
from
'
express
'
import
{
Server
}
from
'
http
'
import
{
randomInt
}
from
'
@shared/core-utils
'
import
{
terminateServer
}
from
'
./utils
'
import
{
getPort
,
randomListen
,
terminateServer
}
from
'
./utils
'
type
BlocklistResponse
=
{
data
:
{
...
...
@@ -15,17 +14,16 @@ export class MockBlocklist {
private
body
:
BlocklistResponse
private
server
:
Server
initialize
()
{
return
new
Promise
<
number
>
(
res
=>
{
const
app
=
express
()
async
initialize
()
{
const
app
=
express
()
app
.
get
(
'
/blocklist
'
,
(
req
:
Request
,
res
:
Response
)
=>
{
return
res
.
json
(
this
.
body
)
})
const
port
=
45000
+
randomInt
(
1
,
1000
)
this
.
server
=
app
.
listen
(
port
,
()
=>
res
(
port
))
app
.
get
(
'
/blocklist
'
,
(
req
:
Request
,
res
:
Response
)
=>
{
return
res
.
json
(
this
.
body
)
})
this
.
server
=
await
randomListen
(
app
)
return
getPort
(
this
.
server
)
}
replace
(
body
:
BlocklistResponse
)
{
...
...
shared/extra-utils/mock-servers/mock-proxy.ts
View file @
d1bfbdeb
import
{
createServer
,
Server
}
from
'
http
'
import
proxy
from
'
proxy
'
import
{
randomInt
}
from
'
@shared/core-utils
'
import
{
terminateServer
}
from
'
./utils
'
import
{
getPort
,
terminateServer
}
from
'
./utils
'
class
MockProxy
{
private
server
:
Server
initialize
()
{
return
new
Promise
<
number
>
(
res
=>
{
const
port
=
46000
+
randomInt
(
1
,
1000
)
this
.
server
=
proxy
(
createServer
())
this
.
server
.
listen
(
port
,
()
=>
res
(
port
))
this
.
server
.
listen
(
0
,
()
=>
res
(
getPort
(
this
.
server
)
))
})
}
...
...
shared/extra-utils/mock-servers/utils.ts
View file @
d1bfbdeb
import
{
Express
}
from
'
express
'
import
{
Server
}
from
'
http
'
import
{
AddressInfo
}
from
'
net
'
function
randomListen
(
app
:
Express
)
{
return
new
Promise
<
Server
>
(
res
=>
{
const
server
=
app
.
listen
(
0
,
()
=>
res
(
server
))
})
}
function
getPort
(
server
:
Server
)
{
const
address
=
server
.
address
()
as
AddressInfo
return
address
.
port
}
function
terminateServer
(
server
:
Server
)
{
if
(
!
server
)
return
Promise
.
resolve
()
...
...
@@ -13,5 +27,7 @@ function terminateServer (server: Server) {
}
export
{
randomListen
,
getPort
,
terminateServer
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment