Skip to content
Snippets Groups Projects
Commit ac784f1c authored by Eric Franz's avatar Eric Franz
Browse files

add helpful error text when formatting is messed up

parent 9761c38e
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,32 @@ module AweSim ...@@ -4,6 +4,32 @@ module AweSim
class Manifest class Manifest
attr_reader :name, :provider, :description, :documentation 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) def self.load(yaml_path)
if File.exist? yaml_path if File.exist? yaml_path
Manifest.new(YAML.load_file yaml_path) Manifest.new(YAML.load_file yaml_path)
...@@ -25,6 +51,8 @@ module AweSim ...@@ -25,6 +51,8 @@ module AweSim
end end
def initialize(opts) def initialize(opts)
raise InvalidContentError.new unless opts.respond_to? :fetch
#FIXME: add sensible default for app name? #FIXME: add sensible default for app name?
@name = opts.fetch("name", "") @name = opts.fetch("name", "")
@provider = opts.fetch("provider", "") @provider = opts.fetch("provider", "")
......
...@@ -5,7 +5,6 @@ require 'pathname' ...@@ -5,7 +5,6 @@ require 'pathname'
class TestManifest < Minitest::Test class TestManifest < Minitest::Test
def setup def setup
@badyaml = "{ app: { version: 1.0 }"
@yaml = %q(--- @yaml = %q(---
provider: Eric Franz provider: Eric Franz
name: Container Fill Sim name: Container Fill Sim
...@@ -24,6 +23,7 @@ documentation: | ...@@ -24,6 +23,7 @@ documentation: |
@appdir = Pathname.new File.realpath Dir.mktmpdir @appdir = Pathname.new File.realpath Dir.mktmpdir
@yaml_path = @appdir.join("manifest.yml") @yaml_path = @appdir.join("manifest.yml")
File.open(@yaml_path, "w") { |f| f.write @yaml } File.open(@yaml_path, "w") { |f| f.write @yaml }
end end
...@@ -49,11 +49,27 @@ documentation: | ...@@ -49,11 +49,27 @@ documentation: |
assert ! manifest.valid? assert ! manifest.valid?
end end
def test_bad_yaml_saves_exception_to_manifest_instance def assert_invalid_manifest_has_exception(manifest, exception_class = nil)
manifest = AweSim::Manifest.load_from_string(@badyaml)
assert manifest.exist? assert manifest.exist?
assert ! manifest.valid? assert ! manifest.valid?
assert ! manifest.exception.nil?, "bad yaml that threw exception should have set exception object, but its nil" 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
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment