Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
awesim-cli
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gateways
awesim-cli
Commits
ac784f1c
Commit
ac784f1c
authored
9 years ago
by
Eric Franz
Browse files
Options
Downloads
Patches
Plain Diff
add helpful error text when formatting is messed up
parent
9761c38e
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/awesim/manifest.rb
+28
-0
28 additions, 0 deletions
lib/awesim/manifest.rb
test/test_manifest.rb
+19
-3
19 additions, 3 deletions
test/test_manifest.rb
with
47 additions
and
3 deletions
lib/awesim/manifest.rb
+
28
−
0
View file @
ac784f1c
...
...
@@ -4,6 +4,32 @@ module AweSim
class
Manifest
attr_reader
:name
,
:provider
,
:description
,
:documentation
class
InvalidContentError
<
StandardError
def
initialize
super
%q(Manifest is not formatted correctly!
Manifest should be in YAML format with markdown for description and documentation:
---
name: Container Fill Sim
description: |
This is a description.
With **markdown**.
And a
* bullet
* sub1
* sub2
* list
documentation: |
Links to support docs should go here.
* [Company Website](https://www.osc.edu)
)
end
end
def
self
.
load
(
yaml_path
)
if
File
.
exist?
yaml_path
Manifest
.
new
(
YAML
.
load_file
yaml_path
)
...
...
@@ -25,6 +51,8 @@ module AweSim
end
def
initialize
(
opts
)
raise
InvalidContentError
.
new
unless
opts
.
respond_to?
:fetch
#FIXME: add sensible default for app name?
@name
=
opts
.
fetch
(
"name"
,
""
)
@provider
=
opts
.
fetch
(
"provider"
,
""
)
...
...
This diff is collapsed.
Click to expand it.
test/test_manifest.rb
+
19
−
3
View file @
ac784f1c
...
...
@@ -5,7 +5,6 @@ require 'pathname'
class
TestManifest
<
Minitest
::
Test
def
setup
@badyaml
=
"{ app: { version: 1.0 }"
@yaml
=
%q(---
provider: Eric Franz
name: Container Fill Sim
...
...
@@ -24,6 +23,7 @@ documentation: |
@appdir
=
Pathname
.
new
File
.
realpath
Dir
.
mktmpdir
@yaml_path
=
@appdir
.
join
(
"manifest.yml"
)
File
.
open
(
@yaml_path
,
"w"
)
{
|
f
|
f
.
write
@yaml
}
end
...
...
@@ -49,11 +49,27 @@ documentation: |
assert
!
manifest
.
valid?
end
def
test_bad_yaml_saves_exception_to_manifest_instance
manifest
=
AweSim
::
Manifest
.
load_from_string
(
@badyaml
)
def
assert_invalid_manifest_has_exception
(
manifest
,
exception_class
=
nil
)
assert
manifest
.
exist?
assert
!
manifest
.
valid?
assert
!
manifest
.
exception
.
nil?
,
"bad yaml that threw exception should have set exception object, but its nil"
assert_instance_of
exception_class
,
manifest
.
exception
if
exception_class
end
def
test_bad_yaml_saves_exception_to_manifest_instance
manifest
=
AweSim
::
Manifest
.
load_from_string
(
"{ app: { version: 1.0 }"
)
assert_invalid_manifest_has_exception
manifest
end
def
test_bad_content_saves_exception_to_manifest_instance
manifest
=
AweSim
::
Manifest
.
load_from_string
(
"--- 123"
)
assert_invalid_manifest_has_exception
manifest
,
AweSim
::
Manifest
::
InvalidContentError
badyaml
=
@appdir
.
join
(
"badman.yml"
)
File
.
open
(
badyaml
,
"w"
)
{
|
f
|
f
.
write
"--- 123"
}
manifest
=
AweSim
::
Manifest
.
load
(
badyaml
)
assert_invalid_manifest_has_exception
manifest
,
AweSim
::
Manifest
::
InvalidContentError
end
end
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