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
67286745
Commit
67286745
authored
7 years ago
by
Kamil Trzcinski
Browse files
Options
Downloads
Patches
Plain Diff
Make tests more reasonable
parent
24fb7afd
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
executors/docker/executor_docker.go
+6
-6
6 additions, 6 deletions
executors/docker/executor_docker.go
executors/docker/executor_docker_test.go
+29
-23
29 additions, 23 deletions
executors/docker/executor_docker_test.go
helpers/shorten_token.go
+7
-0
7 additions, 0 deletions
helpers/shorten_token.go
with
42 additions
and
29 deletions
executors/docker/executor_docker.go
+
6
−
6
View file @
67286745
...
...
@@ -157,16 +157,16 @@ func (s *executor) pullDockerImage(imageName string, ac *types.AuthConfig) (*typ
func
(
s
*
executor
)
isImageUsed
(
name
,
id
string
)
bool
{
if
name
==
id
{
return
fals
e
return
tru
e
}
if
s
.
images
[
name
]
==
id
{
return
fals
e
return
tru
e
}
return
tru
e
return
fals
e
}
func
(
s
*
executor
)
useImage
(
source
,
name
,
id
string
)
{
if
!
s
.
isImageUsed
(
name
,
id
)
{
if
s
.
isImageUsed
(
name
,
id
)
{
return
}
...
...
@@ -176,7 +176,7 @@ func (s *executor) useImage(source, name, id string) {
s
.
images
[
name
]
=
id
pullPolicy
,
_
:=
s
.
Config
.
Docker
.
PullPolicy
.
Get
()
s
.
Println
(
"Using"
,
source
,
"image"
,
id
[
0
:
14
]
,
"for"
,
name
,
"(pull-policy:"
,
pullPolicy
,
")..."
)
s
.
Println
(
"Using"
,
source
,
"image"
,
helpers
.
ShortenTokenN
(
id
,
14
)
,
"for"
,
name
,
"(pull-policy:"
,
pullPolicy
,
")..."
)
}
func
(
s
*
executor
)
getDockerImage
(
imageName
string
,
allowedImages
...
string
)
(
*
types
.
ImageInspect
,
error
)
{
...
...
@@ -211,7 +211,7 @@ func (s *executor) getDockerImage(imageName string, allowedImages ...string) (*t
}
// If already tried to pull image in this run, don't do it again
if
!
s
.
isImageUsed
(
imageName
,
image
.
ID
)
{
if
s
.
isImageUsed
(
imageName
,
image
.
ID
)
{
return
&
image
,
err
}
}
...
...
This diff is collapsed.
Click to expand it.
executors/docker/executor_docker_test.go
+
29
−
23
View file @
67286745
...
...
@@ -148,7 +148,7 @@ func testServiceFromNamedImage(t *testing.T, description, imageName, serviceName
Once
()
c
.
On
(
"ImageInspectWithRaw"
,
e
.
Context
,
imageName
)
.
Return
(
types
.
ImageInspect
{},
nil
,
nil
)
.
Return
(
types
.
ImageInspect
{
ID
:
"ID"
},
nil
,
nil
)
.
Twice
()
c
.
On
(
"ContainerRemove"
,
e
.
Context
,
containerName
,
types
.
ContainerRemoveOptions
{
RemoveVolumes
:
true
,
Force
:
true
})
.
...
...
@@ -235,7 +235,7 @@ func TestDockerForExistingImage(t *testing.T) {
Once
()
c
.
On
(
"ImageInspectWithRaw"
,
e
.
Context
,
"existing"
)
.
Return
(
types
.
ImageInspect
{},
nil
,
nil
)
.
Return
(
types
.
ImageInspect
{
ID
:
"ID"
},
nil
,
nil
)
.
Once
()
image
,
err
:=
e
.
pullDockerImage
(
"existing"
,
nil
)
...
...
@@ -317,7 +317,7 @@ func TestDockerPolicyModeIfNotPresentForExistingImage(t *testing.T) {
e
.
setPolicyMode
(
common
.
PullPolicyIfNotPresent
)
c
.
On
(
"ImageInspectWithRaw"
,
e
.
Context
,
"existing"
)
.
Return
(
types
.
ImageInspect
{},
nil
,
nil
)
.
Return
(
types
.
ImageInspect
{
ID
:
"ID"
},
nil
,
nil
)
.
Once
()
image
,
err
:=
e
.
getDockerImage
(
"existing"
)
...
...
@@ -343,7 +343,7 @@ func TestDockerPolicyModeIfNotPresentForNotExistingImage(t *testing.T) {
Once
()
c
.
On
(
"ImageInspectWithRaw"
,
e
.
Context
,
"not-existing"
)
.
Return
(
types
.
ImageInspect
{},
nil
,
nil
)
.
Return
(
types
.
ImageInspect
{
ID
:
"ID"
},
nil
,
nil
)
.
Once
()
image
,
err
:=
e
.
getDockerImage
(
"not-existing"
)
...
...
@@ -351,7 +351,7 @@ func TestDockerPolicyModeIfNotPresentForNotExistingImage(t *testing.T) {
assert
.
NotNil
(
t
,
image
)
c
.
On
(
"ImageInspectWithRaw"
,
e
.
Context
,
"not-existing"
)
.
Return
(
types
.
ImageInspect
{},
nil
,
nil
)
.
Return
(
types
.
ImageInspect
{
ID
:
"ID"
},
nil
,
nil
)
.
Once
()
// It shouldn't execute the pull for second time
...
...
@@ -369,7 +369,7 @@ func TestDockerPolicyModeAlwaysForExistingImage(t *testing.T) {
e
.
setPolicyMode
(
common
.
PullPolicyAlways
)
c
.
On
(
"ImageInspectWithRaw"
,
e
.
Context
,
"existing"
)
.
Return
(
types
.
ImageInspect
{},
nil
,
nil
)
.
Return
(
types
.
ImageInspect
{
ID
:
"ID"
},
nil
,
nil
)
.
Once
()
options
:=
buildImagePullOptions
(
e
,
"existing:latest"
)
...
...
@@ -378,7 +378,7 @@ func TestDockerPolicyModeAlwaysForExistingImage(t *testing.T) {
Once
()
c
.
On
(
"ImageInspectWithRaw"
,
e
.
Context
,
"existing"
)
.
Return
(
types
.
ImageInspect
{},
nil
,
nil
)
.
Return
(
types
.
ImageInspect
{
ID
:
"ID"
},
nil
,
nil
)
.
Once
()
image
,
err
:=
e
.
getDockerImage
(
"existing"
)
...
...
@@ -395,7 +395,7 @@ func TestDockerPolicyModeAlwaysForLocalOnlyImage(t *testing.T) {
e
.
setPolicyMode
(
common
.
PullPolicyAlways
)
c
.
On
(
"ImageInspectWithRaw"
,
e
.
Context
,
"existing"
)
.
Return
(
types
.
ImageInspect
{},
nil
,
nil
)
.
Return
(
types
.
ImageInspect
{
ID
:
"ID"
},
nil
,
nil
)
.
Once
()
options
:=
buildImagePullOptions
(
e
,
"existing:lastest"
)
...
...
@@ -417,7 +417,7 @@ func TestDockerGetExistingDockerImageIfPullFails(t *testing.T) {
e
.
setPolicyMode
(
common
.
PullPolicyAlways
)
c
.
On
(
"ImageInspectWithRaw"
,
e
.
Context
,
"to-pull"
)
.
Return
(
types
.
ImageInspect
{},
nil
,
nil
)
.
Return
(
types
.
ImageInspect
{
ID
:
"ID"
},
nil
,
nil
)
.
Once
()
options
:=
buildImagePullOptions
(
e
,
"to-pull"
)
...
...
@@ -682,11 +682,14 @@ func TestAuthConfigOverwritingOrder(t *testing.T) {
})
}
func
testGetDockerImage
(
t
*
testing
.
T
,
e
executor
,
imageName
string
,
setClientExpectations
func
(
c
*
docker_helpers
.
MockClient
,
imageName
string
))
{
func
testGetDockerImage
(
t
*
testing
.
T
,
dockerConfig
*
common
.
DockerConfig
,
imageName
string
,
setClientExpectations
func
(
c
*
docker_helpers
.
MockClient
,
imageName
string
))
{
t
.
Run
(
"get:"
+
imageName
,
func
(
t
*
testing
.
T
)
{
var
c
docker_helpers
.
MockClient
defer
c
.
AssertExpectations
(
t
)
e
:=
getAuthConfigTestExecutor
(
t
,
false
)
e
.
Context
=
context
.
Background
()
e
.
Config
.
Docker
=
dockerConfig
e
.
client
=
&
c
setClientExpectations
(
&
c
,
imageName
)
...
...
@@ -697,11 +700,14 @@ func testGetDockerImage(t *testing.T, e executor, imageName string, setClientExp
})
}
func
testDeniesDockerImage
(
t
*
testing
.
T
,
e
executor
,
imageName
string
,
setClientExpectations
func
(
c
*
docker_helpers
.
MockClient
,
imageName
string
))
{
func
testDeniesDockerImage
(
t
*
testing
.
T
,
dockerConfig
*
common
.
DockerConfig
,
imageName
string
,
setClientExpectations
func
(
c
*
docker_helpers
.
MockClient
,
imageName
string
))
{
t
.
Run
(
"deny:"
+
imageName
,
func
(
t
*
testing
.
T
)
{
var
c
docker_helpers
.
MockClient
defer
c
.
AssertExpectations
(
t
)
e
:=
getAuthConfigTestExecutor
(
t
,
false
)
e
.
Context
=
context
.
Background
()
e
.
Config
.
Docker
=
dockerConfig
e
.
client
=
&
c
setClientExpectations
(
&
c
,
imageName
)
...
...
@@ -745,27 +751,27 @@ func TestPullPolicyWhenAlwaysIsSet(t *testing.T) {
remoteImage
:=
"registry.domain.tld:5005/image/name:version"
gitlabImage
:=
"registry.gitlab.tld:1234/image/name:version"
e
:=
getAuthConfigTestExecutor
(
t
,
false
)
e
.
Context
=
context
.
Background
()
e
.
Config
.
Docker
.
PullPolicy
=
common
.
PullPolicyAlways
dockerConfig
:=
&
common
.
DockerConfig
{
PullPolicy
:
common
.
PullPolicyAlways
,
}
testGetDockerImage
(
t
,
e
,
remoteImage
,
addPullsRemoteImageExpectations
)
testDeniesDockerImage
(
t
,
e
,
remoteImage
,
addDeniesPullExpectations
)
testGetDockerImage
(
t
,
dockerConfig
,
remoteImage
,
addPullsRemoteImageExpectations
)
testDeniesDockerImage
(
t
,
dockerConfig
,
remoteImage
,
addDeniesPullExpectations
)
testGetDockerImage
(
t
,
e
,
gitlabImage
,
addPullsRemoteImageExpectations
)
testDeniesDockerImage
(
t
,
e
,
gitlabImage
,
addDeniesPullExpectations
)
testGetDockerImage
(
t
,
dockerConfig
,
gitlabImage
,
addPullsRemoteImageExpectations
)
testDeniesDockerImage
(
t
,
dockerConfig
,
gitlabImage
,
addDeniesPullExpectations
)
}
func
TestPullPolicyWhenIfNotPresentIsSet
(
t
*
testing
.
T
)
{
remoteImage
:=
"registry.domain.tld:5005/image/name:version"
gitlabImage
:=
"registry.gitlab.tld:1234/image/name:version"
e
:=
getAuthConfigTestExecutor
(
t
,
false
)
e
.
Context
=
context
.
Background
()
e
.
Config
.
Docker
.
PullPolicy
=
common
.
PullPolicyIfNotPresent
dockerConfig
:=
&
common
.
DockerConfig
{
PullPolicy
:
common
.
PullPolicyIfNotPresent
,
}
testGetDockerImage
(
t
,
e
,
remoteImage
,
addFindsLocalImageExpectations
)
testGetDockerImage
(
t
,
e
,
gitlabImage
,
addFindsLocalImageExpectations
)
testGetDockerImage
(
t
,
dockerConfig
,
remoteImage
,
addFindsLocalImageExpectations
)
testGetDockerImage
(
t
,
dockerConfig
,
gitlabImage
,
addFindsLocalImageExpectations
)
}
func
TestDockerWatchOn_1_12_4
(
t
*
testing
.
T
)
{
...
...
This diff is collapsed.
Click to expand it.
helpers/shorten_token.go
+
7
−
0
View file @
67286745
...
...
@@ -6,3 +6,10 @@ func ShortenToken(token string) string {
}
return
token
}
func
ShortenTokenN
(
token
string
,
length
int
)
string
{
if
len
(
token
)
>=
length
{
return
token
[
0
:
length
]
}
return
token
}
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