Merge "Add the ability to parse directories"

This commit is contained in:
Jenkins 2015-10-03 18:39:09 +00:00 committed by Gerrit Code Review
commit 580eb0a1b3
3 changed files with 48 additions and 1 deletions

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
from oslo_config import cfg
from oslo_log import log as logging
@ -46,7 +48,17 @@ class Builder(object):
self.parser = YamlParser()
def load_files(self, path):
self.parser.parse(path)
files_to_process = []
if os.path.isdir(path):
files_to_process.extend([os.path.join(path, f)
for f in os.listdir(path)
if (f.endswith('.yaml')
or f.endswith('.yml'))])
else:
files_to_process.append(path)
for fn in files_to_process:
self.parser.parse(fn)
def update_dashboard(self, path):
self.load_files(path)

View File

@ -58,6 +58,40 @@ class TestCaseValidateScenarios(TestWithScenarios, TestCase):
class TestCaseValidate(TestCase):
def test_validate_directory_success(self):
path = os.path.join(
os.path.dirname(__file__), '../fixtures/cmd/validate/test0001')
required = [
'SUCCESS!',
]
stdout, stderr = self.shell(
'validate %s' % path, exitcodes=[0])
for r in required:
self.assertThat(
(stdout + stderr),
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
def test_validate_directory_invalid(self):
path = os.path.join(
os.path.dirname(__file__), '../fixtures/cmd/validate/__invalid__')
self._validate_invalid_file_or_directory(path)
def test_validate_file_invalid(self):
path = os.path.join(
os.path.dirname(__file__), '../fixtures/cmd/validate/invalid.yaml')
self._validate_invalid_file_or_directory(path)
def _validate_invalid_file_or_directory(self, path):
required = [
'%s: ERROR: \[Errno 2\] No such file or directory:' % path,
]
stdout, stderr = self.shell(
'validate %s' % path, exitcodes=[1])
for r in required:
self.assertThat(
(stdout + stderr),
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
def test_validate_without_path(self):
required = [
'.*?^usage: grafana-dashboards validate \[-h\] path',

View File

@ -0,0 +1 @@
../good-dashboard-0001.yaml