Add the ability to parse directories
Change-Id: I0ff6c803608d91e04b8e40750265157d3f4f7530 Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
parent
f4b18fdd74
commit
609733c116
@ -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)
|
||||
|
@ -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',
|
||||
|
1
tests/fixtures/cmd/validate/test0001/good-dashboard-0001.yaml
vendored
Symbolic link
1
tests/fixtures/cmd/validate/test0001/good-dashboard-0001.yaml
vendored
Symbolic link
@ -0,0 +1 @@
|
||||
../good-dashboard-0001.yaml
|
Loading…
x
Reference in New Issue
Block a user