Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gitlab-runner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Seipel
gitlab-runner
Commits
b3e98660
Unverified
Commit
b3e98660
authored
6 years ago
by
Steve Azzopardi
Browse files
Options
Downloads
Patches
Plain Diff
Add error response code for terminalConn.Start
parent
565d5042
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
executors/docker/terminal.go
+8
-4
8 additions, 4 deletions
executors/docker/terminal.go
executors/docker/terminal_test.go
+73
-0
73 additions, 0 deletions
executors/docker/terminal_test.go
with
81 additions
and
4 deletions
executors/docker/terminal.go
+
8
−
4
View file @
b3e98660
...
@@ -86,12 +86,16 @@ func (t terminalConn) Start(w http.ResponseWriter, r *http.Request, timeoutCh, d
...
@@ -86,12 +86,16 @@ func (t terminalConn) Start(w http.ResponseWriter, r *http.Request, timeoutCh, d
exec
,
err
:=
t
.
client
.
ContainerExecCreate
(
t
.
ctx
,
t
.
containerID
,
execConfig
)
exec
,
err
:=
t
.
client
.
ContainerExecCreate
(
t
.
ctx
,
t
.
containerID
,
execConfig
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
logger
.
Errorln
(
"failed to create exec container for terminal:"
,
err
)
t
.
logger
.
Errorln
(
"Failed to create exec container for terminal:"
,
err
)
http
.
Error
(
w
,
http
.
StatusText
(
http
.
StatusInternalServerError
),
http
.
StatusInternalServerError
)
return
}
}
resp
,
err
:=
t
.
client
.
ContainerExecAttach
(
t
.
ctx
,
exec
.
ID
,
execConfig
)
resp
,
err
:=
t
.
client
.
ContainerExecAttach
(
t
.
ctx
,
exec
.
ID
,
execConfig
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
logger
.
Errorln
(
"failed to exec attach to container for terminal:"
,
err
)
t
.
logger
.
Errorln
(
"Failed to exec attach to container for terminal:"
,
err
)
http
.
Error
(
w
,
http
.
StatusText
(
http
.
StatusInternalServerError
),
http
.
StatusInternalServerError
)
return
}
}
dockerTTY
:=
newDockerTTY
(
&
resp
)
dockerTTY
:=
newDockerTTY
(
&
resp
)
...
@@ -105,9 +109,9 @@ func (t terminalConn) Start(w http.ResponseWriter, r *http.Request, timeoutCh, d
...
@@ -105,9 +109,9 @@ func (t terminalConn) Start(w http.ResponseWriter, r *http.Request, timeoutCh, d
stopCh
:=
proxy
.
GetStopCh
()
stopCh
:=
proxy
.
GetStopCh
()
if
err
!=
nil
{
if
err
!=
nil
{
stopCh
<-
fmt
.
Errorf
(
"
B
uild container exited with %q"
,
err
)
stopCh
<-
fmt
.
Errorf
(
"
b
uild container exited with %q"
,
err
)
}
else
{
}
else
{
stopCh
<-
fmt
.
Errorf
(
"
B
uild container exited"
)
stopCh
<-
errors
.
New
(
"
b
uild container exited"
)
}
}
}()
}()
...
...
This diff is collapsed.
Click to expand it.
executors/docker/terminal_test.go
+
73
−
0
View file @
b3e98660
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"bufio"
"bufio"
"bytes"
"bytes"
"context"
"context"
"errors"
"net"
"net"
"net/http"
"net/http"
"net/http/httptest"
"net/http/httptest"
...
@@ -167,6 +168,78 @@ func TestCommandExecutor_Connect(t *testing.T) {
...
@@ -167,6 +168,78 @@ func TestCommandExecutor_Connect(t *testing.T) {
assert
.
IsType
(
t
,
terminalConn
{},
conn
)
assert
.
IsType
(
t
,
terminalConn
{},
conn
)
}
}
func
TestTerminalConn_FailToStart
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
containerExecCreateErr
error
containerExecAttachErr
error
}{
{
name
:
"Failed to create exec container"
,
containerExecCreateErr
:
errors
.
New
(
"failed to create exec container"
),
containerExecAttachErr
:
nil
,
},
{
name
:
"Failed to attach exec container"
,
containerExecCreateErr
:
nil
,
containerExecAttachErr
:
errors
.
New
(
"failed to attach exec container"
),
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
c
:=
&
docker_helpers
.
MockClient
{}
s
:=
commandExecutor
{
executor
:
executor
{
AbstractExecutor
:
executors
.
AbstractExecutor
{
Context
:
context
.
Background
(),
BuildShell
:
&
common
.
ShellConfiguration
{
DockerCommand
:
[]
string
{
"/bin/sh"
},
},
},
client
:
c
,
},
buildContainer
:
&
types
.
ContainerJSON
{
ContainerJSONBase
:
&
types
.
ContainerJSONBase
{
ID
:
"1234"
,
},
},
}
c
.
On
(
"ContainerInspect"
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
types
.
ContainerJSON
{
ContainerJSONBase
:
&
types
.
ContainerJSONBase
{
State
:
&
types
.
ContainerState
{
Running
:
true
,
},
},
},
nil
)
c
.
On
(
"ContainerExecCreate"
,
mock
.
Anything
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
types
.
IDResponse
{},
test
.
containerExecCreateErr
,
)
c
.
On
(
"ContainerExecAttach"
,
mock
.
Anything
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
types
.
HijackedResponse
{},
test
.
containerExecAttachErr
,
)
conn
,
err
:=
s
.
Connect
()
require
.
NoError
(
t
,
err
)
timeoutCh
:=
make
(
chan
error
)
disconnectCh
:=
make
(
chan
error
)
w
:=
httptest
.
NewRecorder
()
req
:=
httptest
.
NewRequest
(
http
.
MethodGet
,
"wss://example.com/foo"
,
nil
)
conn
.
Start
(
w
,
req
,
timeoutCh
,
disconnectCh
)
resp
:=
w
.
Result
()
assert
.
Equal
(
t
,
http
.
StatusInternalServerError
,
resp
.
StatusCode
)
})
}
}
type
nopReader
struct
{
type
nopReader
struct
{
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment