Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Job Queues
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Go
Services
Job Queues
Commits
7c8763b8
Verified
Commit
7c8763b8
authored
1 year ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
fix: ci pipeline
parent
b4d6a6bb
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
runnable-mail_test.go
+29
-18
29 additions, 18 deletions
runnable-mail_test.go
runnable-sftp_test.go
+26
-8
26 additions, 8 deletions
runnable-sftp_test.go
utils.go
+51
-3
51 additions, 3 deletions
utils.go
with
106 additions
and
29 deletions
runnable-mail_test.go
+
29
−
18
View file @
7c8763b8
...
...
@@ -10,9 +10,11 @@ import (
"time"
)
func
startTestSMTPDockerImageAndContainer
(
t
*
testing
.
T
,
ctx
context
.
Context
)
(
string
,
error
)
{
func
startTestSMTPDockerImageAndContainer
(
t
*
testing
.
T
,
ctx
context
.
Context
)
(
*
mockPortContainer
,
error
)
{
t
.
Helper
()
mc
:=
&
mockPortContainer
{}
smtpPortMap
:=
nat
.
PortMap
{
"1025/tcp"
:
[]
nat
.
PortBinding
{
{
...
...
@@ -28,24 +30,33 @@ func startTestSMTPDockerImageAndContainer(t *testing.T, ctx context.Context) (st
},
}
smtpCmd
:=
[]
string
{}
// Ihr Command hier, falls nötig
smtpVolume
:=
""
// Ihr Volume hier
smtpPorts
,
err
:=
startTestDockerImageAndContainer
(
t
,
ctx
,
"axllent/mailpit"
,
smtpPortMap
,
smtpCmd
,
smtpVolume
)
mr
:=
&
mockRunnable
{
ctx
:
ctx
,
imageName
:
"axllent/mailpit"
,
portMap
:
smtpPortMap
,
cmd
:
[]
string
{},
volume
:
""
,
t
:
t
,
}
smtpPorts
,
err
:=
mr
.
startTestDockerImageAndContainer
()
if
err
!=
nil
{
return
""
,
err
return
mc
,
err
}
pp
:=
*
smtpPorts
px
,
ok
:=
pp
[
"1025/tcp"
]
if
!
ok
{
return
""
,
fmt
.
Errorf
(
"1025/tcp port not found"
)
return
mc
,
fmt
.
Errorf
(
"1025/tcp port not found"
)
}
smtpPort
:=
px
[
0
]
.
HostPort
return
smtpPort
,
nil
mc
.
setPort
(
smtpPort
)
return
mc
,
nil
//cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
//if err != nil {
...
...
@@ -152,23 +163,23 @@ func TestMailRunner(t *testing.T) {
//portAsString := fmt.Sprintf("%d", portAsInt)
//_ = listener.Close()
var
p
ortAsString
string
var
p
c
*
mockPortContainer
var
err
error
done
:=
make
(
chan
bool
)
go
func
()
{
p
ortAsString
,
err
=
startTestSMTPDockerImageAndContainer
(
t
,
ctx
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
cancel
()
}
done
<-
true
}()
//
go func() {
p
c
,
err
=
startTestSMTPDockerImageAndContainer
(
t
,
ctx
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
cancel
()
}
done
<-
true
//
}()
waitCtx
,
waitCancel
:=
context
.
WithTimeout
(
ctx
,
60
*
time
.
Second
)
defer
waitCancel
()
for
{
conn
,
err
:=
net
.
DialTimeout
(
"tcp"
,
net
.
JoinHostPort
(
DOCKER_TEST_HOST_IP
,
p
ortAsString
),
1
*
time
.
Second
)
conn
,
err
:=
net
.
DialTimeout
(
"tcp"
,
net
.
JoinHostPort
(
DOCKER_TEST_HOST_IP
,
p
c
.
getPort
()
),
1
*
time
.
Second
)
if
err
==
nil
{
err
=
conn
.
Close
()
assert
.
Nil
(
t
,
err
)
...
...
@@ -192,7 +203,7 @@ func TestMailRunner(t *testing.T) {
Subject
:
"this is a test"
,
Body
:
"this is the body"
,
Server
:
DOCKER_TEST_HOST_IP
,
Port
:
p
ortAsString
,
Port
:
p
c
.
getPort
()
,
Username
:
""
,
Password
:
""
,
Headers
:
map
[
string
]
string
{
...
...
This diff is collapsed.
Click to expand it.
runnable-sftp_test.go
+
26
−
8
View file @
7c8763b8
...
...
@@ -12,7 +12,7 @@ import (
"time"
)
func
startSFTPTestDockerImageAndContainer
(
t
*
testing
.
T
,
volume
string
,
ctx
context
.
Context
)
(
string
,
error
)
{
func
startSFTPTestDockerImageAndContainer
(
t
*
testing
.
T
,
volume
Path
string
,
ctx
context
.
Context
)
(
string
,
error
)
{
t
.
Helper
()
sftpPortMap
:=
nat
.
PortMap
{
...
...
@@ -25,8 +25,18 @@ func startSFTPTestDockerImageAndContainer(t *testing.T, volume string, ctx conte
}
sftpCmd
:=
[]
string
{
"demo:secret:::upload"
}
sftpVolume
:=
volume
// Ihr Volume hier
sftpPorts
,
err
:=
startTestDockerImageAndContainer
(
t
,
ctx
,
"atmoz/sftp:alpine"
,
sftpPortMap
,
sftpCmd
,
sftpVolume
)
sftpVolume
:=
volumePath
// Ihr Volume hier
mr
:=
&
mockRunnable
{
ctx
:
ctx
,
imageName
:
"atmoz/sftp:alpine"
,
portMap
:
sftpPortMap
,
cmd
:
sftpCmd
,
volume
:
sftpVolume
,
t
:
t
,
}
sftpPorts
,
err
:=
mr
.
startTestDockerImageAndContainer
()
if
err
!=
nil
{
return
""
,
err
}
...
...
@@ -240,6 +250,12 @@ func TestSFTPCRunnerLocalToRemote(t *testing.T) {
}
func
TestSFTPCRunnerRemoteToLocal
(
t
*
testing
.
T
)
{
if
os
.
Getenv
(
"CI_SERVER"
)
!=
""
{
t
.
Skip
(
"Skipping test because CI_SERVER is set"
)
// TODO: run this test in CI
}
ctb
:=
context
.
Background
()
ctx
,
cancel
:=
context
.
WithCancel
(
ctb
)
t
.
Cleanup
(
func
()
{
...
...
@@ -266,23 +282,26 @@ func TestSFTPCRunnerRemoteToLocal(t *testing.T) {
}
}
var
portAsString
string
var
mpContainer
mockPortContainer
var
err
error
done
:=
make
(
chan
bool
)
go
func
()
{
portAsString
,
err
=
startSFTPTestDockerImageAndContainer
(
t
,
tempSrcDir
,
ctx
)
portAsString
,
err
:
=
startSFTPTestDockerImageAndContainer
(
t
,
tempSrcDir
,
ctx
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
cancel
()
}
mpContainer
.
setPort
(
portAsString
)
done
<-
true
}()
waitCtx
,
waitCancel
:=
context
.
WithTimeout
(
ctx
,
60
*
time
.
Second
)
defer
waitCancel
()
for
{
conn
,
err
:=
net
.
DialTimeout
(
"tcp"
,
net
.
JoinHostPort
(
DOCKER_TEST_HOST_IP
,
portAsString
),
1
*
time
.
Second
)
conn
,
err
:=
net
.
DialTimeout
(
"tcp"
,
net
.
JoinHostPort
(
DOCKER_TEST_HOST_IP
,
mpContainer
.
getPort
()
),
1
*
time
.
Second
)
if
err
==
nil
{
err
=
conn
.
Close
()
assert
.
Nil
(
t
,
err
)
...
...
@@ -302,8 +321,7 @@ func TestSFTPCRunnerRemoteToLocal(t *testing.T) {
tempDir
:=
t
.
TempDir
()
portAsInt
,
err
:=
strconv
.
Atoi
(
portAsString
)
assert
.
NoError
(
t
,
err
)
portAsInt
:=
mpContainer
.
getPortAsInt
()
sftpRunnable
:=
&
SFTPRunnable
{
Host
:
DOCKER_TEST_HOST_IP
,
...
...
This diff is collapsed.
Click to expand it.
utils.go
+
51
−
3
View file @
7c8763b8
...
...
@@ -6,6 +6,8 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"strconv"
"sync"
"testing"
"time"
)
...
...
@@ -14,9 +16,55 @@ const (
DOCKER_TEST_HOST_IP
=
"172.17.0.1"
)
func
startTestDockerImageAndContainer
(
t
*
testing
.
T
,
ctx
context
.
Context
,
imageName
string
,
portMap
nat
.
PortMap
,
cmd
[]
string
,
volume
string
)
(
*
nat
.
PortMap
,
error
)
{
type
mockPortContainer
struct
{
mu
sync
.
Mutex
port
string
}
func
(
mp
*
mockPortContainer
)
getPort
()
string
{
mp
.
mu
.
Lock
()
defer
mp
.
mu
.
Unlock
()
return
mp
.
port
}
func
(
mp
*
mockPortContainer
)
setPort
(
port
string
)
{
mp
.
mu
.
Lock
()
defer
mp
.
mu
.
Unlock
()
mp
.
port
=
port
}
func
(
mp
*
mockPortContainer
)
getPortAsInt
()
int
{
mp
.
mu
.
Lock
()
defer
mp
.
mu
.
Unlock
()
port
,
_
:=
strconv
.
Atoi
(
mp
.
port
)
return
port
}
type
mockRunnable
struct
{
mu
sync
.
Mutex
ctx
context
.
Context
imageName
string
portMap
nat
.
PortMap
cmd
[]
string
volume
string
t
*
testing
.
T
hostPort
string
creatVol
bool
}
func
(
mr
*
mockRunnable
)
startTestDockerImageAndContainer
()
(
*
nat
.
PortMap
,
error
)
{
mr
.
mu
.
Lock
()
defer
mr
.
mu
.
Unlock
()
t
:=
mr
.
t
t
.
Helper
()
ctx
:=
mr
.
ctx
imageName
:=
mr
.
imageName
portMap
:=
mr
.
portMap
cmd
:=
mr
.
cmd
volPath
:=
mr
.
volume
cli
,
err
:=
client
.
NewClientWithOpts
(
client
.
FromEnv
,
client
.
WithAPIVersionNegotiation
())
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -37,8 +85,8 @@ func startTestDockerImageAndContainer(t *testing.T, ctx context.Context, imageNa
PortBindings
:
portMap
,
}
if
vol
ume
!=
""
{
hostConfig
.
Binds
=
append
(
hostConfig
.
Binds
,
vol
ume
+
":/home/demo/upload"
)
if
vol
Path
!=
""
{
hostConfig
.
Binds
=
append
(
hostConfig
.
Binds
,
vol
Path
+
":/home/demo/upload"
)
}
resp
,
err
:=
cli
.
ContainerCreate
(
ctx
,
&
container
.
Config
{
...
...
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