Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
accountserver
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai3
accountserver
Commits
62655bdc
Commit
62655bdc
authored
Jun 20, 2018
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wait for the test LDAP server to start
parent
02d7c9c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
1 deletion
+24
-1
backend/ldap_server_test.go
backend/ldap_server_test.go
+24
-1
No files found.
backend/ldap_server_test.go
View file @
62655bdc
package
backend
import
(
"errors"
"fmt"
"io/ioutil"
"net"
"os"
"os/exec"
"testing"
"time"
...
...
@@ -14,6 +17,22 @@ type testLDAPServerConfig struct {
LDIFs
[]
string
}
func
waitForPort
(
port
int
,
timeout
time
.
Duration
)
error
{
addr
:=
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
port
)
deadline
:=
time
.
Now
()
.
Add
(
timeout
)
for
{
conn
,
err
:=
net
.
Dial
(
"tcp"
,
addr
)
if
err
==
nil
{
conn
.
Close
()
return
nil
}
time
.
Sleep
(
200
*
time
.
Millisecond
)
if
time
.
Now
()
.
After
(
deadline
)
{
return
errors
.
New
(
"server did not come up within the deadline"
)
}
}
}
func
startTestLDAPServer
(
t
testing
.
TB
,
config
*
testLDAPServerConfig
)
func
()
{
tmpf
,
err
:=
ioutil
.
TempFile
(
""
,
""
)
if
err
!=
nil
{
...
...
@@ -29,14 +48,18 @@ ldap.port=%d
args
:=
[]
string
{
tmpf
.
Name
()}
args
=
append
(
args
,
config
.
LDIFs
...
)
proc
:=
exec
.
Command
(
"./unboundid-ldap-server/bin/unboundid-ldap-server"
,
args
...
)
proc
.
Stdout
=
os
.
Stdout
proc
.
Stderr
=
os
.
Stderr
if
err
:=
proc
.
Start
();
err
!=
nil
{
t
.
Fatalf
(
"error starting LDAP server: %v"
,
err
)
}
time
.
Sleep
(
1
*
time
.
Second
)
waitForPort
(
config
.
Port
,
5
*
time
.
Second
)
return
func
()
{
proc
.
Process
.
Kill
()
proc
.
Wait
()
os
.
Remove
(
tmpf
.
Name
())
}
}
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