Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Vault
Commits
0e9db8be
Unverified
Commit
0e9db8be
authored
3 years ago
by
Nick Cabatoff
Committed by
GitHub
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Add ability to capture container logs, and have mssql test helper use it (#13272)
parent
0514a8e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
helper/testhelpers/docker/testhelpers.go
+18
-0
helper/testhelpers/docker/testhelpers.go
helper/testhelpers/mssql/mssqlhelper.go
+5
-0
helper/testhelpers/mssql/mssqlhelper.go
with
23 additions
and
0 deletions
+23
-0
helper/testhelpers/docker/testhelpers.go
+
18
-
0
View file @
0e9db8be
...
@@ -40,6 +40,7 @@ type RunOptions struct {
...
@@ -40,6 +40,7 @@ type RunOptions struct {
DoNotAutoRemove
bool
DoNotAutoRemove
bool
AuthUsername
string
AuthUsername
string
AuthPassword
string
AuthPassword
string
LogConsumer
func
(
string
)
}
}
func
NewServiceRunner
(
opts
RunOptions
)
(
*
Runner
,
error
)
{
func
NewServiceRunner
(
opts
RunOptions
)
(
*
Runner
,
error
)
{
...
@@ -135,6 +136,23 @@ func (d *Runner) StartService(ctx context.Context, connect ServiceAdapter) (*Ser
...
@@ -135,6 +136,23 @@ func (d *Runner) StartService(ctx context.Context, connect ServiceAdapter) (*Ser
}
}
cleanup
:=
func
()
{
cleanup
:=
func
()
{
if
d
.
RunOptions
.
LogConsumer
!=
nil
{
rc
,
err
:=
d
.
DockerAPI
.
ContainerLogs
(
ctx
,
container
.
ID
,
types
.
ContainerLogsOptions
{
ShowStdout
:
true
,
ShowStderr
:
true
,
Timestamps
:
true
,
Details
:
true
,
})
if
err
==
nil
{
b
,
err
:=
ioutil
.
ReadAll
(
rc
)
if
err
!=
nil
{
d
.
RunOptions
.
LogConsumer
(
fmt
.
Sprintf
(
"error reading container logs, err=%v, read: %s"
,
err
,
string
(
b
)))
}
else
{
d
.
RunOptions
.
LogConsumer
(
string
(
b
))
}
}
}
for
i
:=
0
;
i
<
10
;
i
++
{
for
i
:=
0
;
i
<
10
;
i
++
{
err
:=
d
.
DockerAPI
.
ContainerRemove
(
ctx
,
container
.
ID
,
types
.
ContainerRemoveOptions
{
Force
:
true
})
err
:=
d
.
DockerAPI
.
ContainerRemove
(
ctx
,
container
.
ID
,
types
.
ContainerRemoveOptions
{
Force
:
true
})
if
err
==
nil
{
if
err
==
nil
{
...
...
This diff is collapsed.
Click to expand it.
helper/testhelpers/mssql/mssqlhelper.go
+
5
-
0
View file @
0e9db8be
...
@@ -32,6 +32,11 @@ func PrepareMSSQLTestContainer(t *testing.T) (cleanup func(), retURL string) {
...
@@ -32,6 +32,11 @@ func PrepareMSSQLTestContainer(t *testing.T) (cleanup func(), retURL string) {
ImageTag
:
"2017-latest-ubuntu"
,
ImageTag
:
"2017-latest-ubuntu"
,
Env
:
[]
string
{
"ACCEPT_EULA=Y"
,
"SA_PASSWORD="
+
mssqlPassword
},
Env
:
[]
string
{
"ACCEPT_EULA=Y"
,
"SA_PASSWORD="
+
mssqlPassword
},
Ports
:
[]
string
{
"1433/tcp"
},
Ports
:
[]
string
{
"1433/tcp"
},
LogConsumer
:
func
(
s
string
)
{
if
t
.
Failed
()
{
t
.
Logf
(
"container logs: %s"
,
s
)
}
},
})
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Could not start docker MSSQL: %s"
,
err
)
t
.
Fatalf
(
"Could not start docker MSSQL: %s"
,
err
)
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help