Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
f0479ba1
Unverified
Commit
f0479ba1
authored
Oct 21, 2022
by
MatteoPologruto
Committed by
GitHub
Oct 21, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[skip-changelog] Add function to spawn a server that responds with error code (#1936)
parent
bdd0cf92
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
0 deletions
+28
-0
internal/integrationtest/http_server.go
internal/integrationtest/http_server.go
+28
-0
No files found.
internal/integrationtest/http_server.go
View file @
f0479ba1
...
@@ -51,3 +51,31 @@ func (env *Environment) HTTPServeFile(port uint16, path *paths.Path) *url.URL {
...
@@ -51,3 +51,31 @@ func (env *Environment) HTTPServeFile(port uint16, path *paths.Path) *url.URL {
return
fileURL
return
fileURL
}
}
// HTTPServeFileError spawns an http server that serves a single file and responds
// with the given error code.
func
(
env
*
Environment
)
HTTPServeFileError
(
port
uint16
,
path
*
paths
.
Path
,
code
int
)
*
url
.
URL
{
mux
:=
http
.
NewServeMux
()
mux
.
HandleFunc
(
"/"
+
path
.
Base
(),
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
code
)
})
server
:=
&
http
.
Server
{
Addr
:
fmt
.
Sprintf
(
":%d"
,
port
),
Handler
:
mux
,
}
t
:=
env
.
T
()
fileURL
,
err
:=
url
.
Parse
(
fmt
.
Sprintf
(
"http://127.0.0.1:%d/%s"
,
port
,
path
.
Base
()))
require
.
NoError
(
t
,
err
)
go
func
()
{
err
:=
server
.
ListenAndServe
()
require
.
Equal
(
t
,
err
,
http
.
ErrServerClosed
)
}()
env
.
RegisterCleanUpCallback
(
func
()
{
server
.
Close
()
})
return
fileURL
}
Write
Preview
Markdown
is supported
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