Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
9f40e3cb
Commit
9f40e3cb
authored
May 12, 2020
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add parser for helm list
Will be required in later MRs to parse the cluster_application artifact
parent
3b4b79b3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
113 additions
and
0 deletions
+113
-0
lib/gitlab/kubernetes/helm/parsers/list_v2.rb
lib/gitlab/kubernetes/helm/parsers/list_v2.rb
+27
-0
spec/lib/gitlab/kubernetes/helm/parsers/list_v2_spec.rb
spec/lib/gitlab/kubernetes/helm/parsers/list_v2_spec.rb
+86
-0
No files found.
lib/gitlab/kubernetes/helm/parsers/list_v2.rb
0 → 100644
View file @
9f40e3cb
# frozen_string_literal: true
module
Gitlab
module
Kubernetes
module
Helm
module
Parsers
# Parses Helm v2 list (JSON) output
class
ListV2
ParserError
=
Class
.
new
(
StandardError
)
attr_reader
:contents
,
:json
def
initialize
(
contents
)
@contents
=
contents
@json
=
Gitlab
::
Json
.
parse
(
contents
)
rescue
JSON
::
ParserError
=>
e
raise
ParserError
,
e
.
message
end
def
releases
@releases
||=
json
[
"Releases"
]
||
[]
end
end
end
end
end
end
spec/lib/gitlab/kubernetes/helm/parsers/list_v2_spec.rb
0 → 100644
View file @
9f40e3cb
# frozen_string_literal: true
require
'fast_spec_helper'
describe
Gitlab
::
Kubernetes
::
Helm
::
Parsers
::
ListV2
do
let
(
:valid_file_contents
)
do
<<~
EOF
{
"Next": "",
"Releases": [
{
"Name": "certmanager",
"Revision": 2,
"Updated": "Sun Mar 29 06:55:42 2020",
"Status": "DEPLOYED",
"Chart": "cert-manager-v0.10.1",
"AppVersion": "v0.10.1",
"Namespace": "gitlab-managed-apps"
},
{
"Name": "certmanager-crds",
"Revision": 2,
"Updated": "Sun Mar 29 06:55:32 2020",
"Status": "DEPLOYED",
"Chart": "cert-manager-crds-v0.2.0",
"AppVersion": "release-0.10",
"Namespace": "gitlab-managed-apps"
},
{
"Name": "certmanager-issuer",
"Revision": 1,
"Updated": "Tue Feb 18 10:04:04 2020",
"Status": "FAILED",
"Chart": "cert-manager-issuer-v0.1.0",
"AppVersion": "",
"Namespace": "gitlab-managed-apps"
},
{
"Name": "runner",
"Revision": 2,
"Updated": "Sun Mar 29 07:01:01 2020",
"Status": "DEPLOYED",
"Chart": "gitlab-runner-0.14.0",
"AppVersion": "12.8.0",
"Namespace": "gitlab-managed-apps"
}
]
}
EOF
end
describe
'#initialize'
do
it
'initializes without error'
do
expect
do
described_class
.
new
(
valid_file_contents
)
end
.
not_to
raise_error
end
it
'raises an error on invalid JSON'
do
expect
do
described_class
.
new
(
''
)
end
.
to
raise_error
(
described_class
::
ParserError
,
'A JSON text must at least contain two octets!'
)
end
end
describe
'#releases'
do
subject
(
:list_v2
)
{
described_class
.
new
(
valid_file_contents
)
}
it
'returns list of releases'
do
expect
(
list_v2
.
releases
).
to
match
([
a_hash_including
(
'Name'
=>
'certmanager'
,
'Status'
=>
'DEPLOYED'
),
a_hash_including
(
'Name'
=>
'certmanager-crds'
,
'Status'
=>
'DEPLOYED'
),
a_hash_including
(
'Name'
=>
'certmanager-issuer'
,
'Status'
=>
'FAILED'
),
a_hash_including
(
'Name'
=>
'runner'
,
'Status'
=>
'DEPLOYED'
)
])
end
context
'empty Releases'
do
let
(
:valid_file_contents
)
{
'{}'
}
it
'returns an empty array'
do
expect
(
list_v2
.
releases
).
to
eq
([])
end
end
end
end
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