Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
Workers
Base Worker
Commits
fd1a2b1b
Commit
fd1a2b1b
authored
4 years ago
by
Bastien Abadie
Browse files
Options
Downloads
Patches
Plain Diff
Cover the 3 cases
parent
b7906fc5
No related branches found
No related tags found
1 merge request
!20
Load configuration from API or local file
Pipeline
#77953
passed
4 years ago
Stage: test
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_base_worker.py
+25
-0
25 additions, 0 deletions
tests/test_base_worker.py
with
25 additions
and
0 deletions
tests/test_base_worker.py
+
25
−
0
View file @
fd1a2b1b
...
...
@@ -34,10 +34,29 @@ def test_init_var_ponos_data_given(monkeypatch):
def
test_init_var_worker_version_id_missing
(
monkeypatch
):
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
worker
"
])
monkeypatch
.
delenv
(
"
WORKER_VERSION_ID
"
)
worker
=
BaseWorker
()
worker
.
configure
()
assert
worker
.
worker_version_id
is
None
assert
worker
.
is_read_only
is
True
assert
worker
.
config
==
{}
# default empty case
def
test_init_var_worker_local_file
(
monkeypatch
,
tmp_path
):
# Build a dummy yaml config file
config
=
tmp_path
/
"
config.yml
"
config
.
write_text
(
"
---
\n
localKey: abcdef123
"
)
monkeypatch
.
setattr
(
sys
,
"
argv
"
,
[
"
worker
"
,
"
-c
"
,
str
(
config
)])
monkeypatch
.
delenv
(
"
WORKER_VERSION_ID
"
)
worker
=
BaseWorker
()
worker
.
configure
()
assert
worker
.
worker_version_id
is
None
assert
worker
.
is_read_only
is
True
assert
worker
.
config
==
{
"
localKey
"
:
"
abcdef123
"
}
# Use a local file for devs
config
.
unlink
()
def
test_cli_default
(
mocker
,
mock_worker_version_api
):
...
...
@@ -46,6 +65,8 @@ def test_cli_default(mocker, mock_worker_version_api):
assert
not
spy
.
called
assert
logger
.
level
==
logging
.
NOTSET
assert
not
hasattr
(
worker
,
"
api_client
"
)
mocker
.
patch
.
object
(
sys
,
"
argv
"
,
[
"
worker
"
])
worker
.
configure
()
assert
spy
.
called
...
...
@@ -53,6 +74,9 @@ def test_cli_default(mocker, mock_worker_version_api):
assert
not
worker
.
args
.
verbose
assert
logger
.
level
==
logging
.
NOTSET
assert
worker
.
api_client
assert
worker
.
worker_version_id
==
"
12341234-1234-1234-1234-123412341234
"
assert
worker
.
is_read_only
is
False
assert
worker
.
config
==
{
"
someKey
"
:
"
someValue
"
}
# from API
logger
.
setLevel
(
logging
.
NOTSET
)
...
...
@@ -74,5 +98,6 @@ def test_cli_arg_verbose_given(mocker, mock_worker_version_api):
assert
worker
.
api_client
assert
worker
.
worker_version_id
==
"
12341234-1234-1234-1234-123412341234
"
assert
worker
.
is_read_only
is
False
assert
worker
.
config
==
{
"
someKey
"
:
"
someValue
"
}
# from API
logger
.
setLevel
(
logging
.
NOTSET
)
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