From 994a13c1ca926ae8ac464aa313ac3e710bc7d232 Mon Sep 17 00:00:00 2001
From: Krysta <klknight23@gmail.com>
Date: Mon, 9 Apr 2018 13:42:51 -0500
Subject: [PATCH] Check that Pegleg only considers YAML

Add a unit test to make sure Pegleg only considers YAML files
when linting

Fixes a typo in filename for test_selectable_linting

Changed site_yaml file stucture to more resemble real site
directory structure

Change-Id: Ib1520f9509d279d88b4408858878022fb05c7707
---
 site_yamls/{ => site}/site-definition.yaml    |  0
 .../tests/unit/test_engine_util_files.py      | 30 +++++++++++++++++++
 ..._linitng.py => test_selectable_linting.py} |  0
 3 files changed, 30 insertions(+)
 rename site_yamls/{ => site}/site-definition.yaml (100%)
 create mode 100644 src/bin/pegleg/tests/unit/test_engine_util_files.py
 rename src/bin/pegleg/tests/unit/{test_selectable_linitng.py => test_selectable_linting.py} (100%)

diff --git a/site_yamls/site-definition.yaml b/site_yamls/site/site-definition.yaml
similarity index 100%
rename from site_yamls/site-definition.yaml
rename to site_yamls/site/site-definition.yaml
diff --git a/src/bin/pegleg/tests/unit/test_engine_util_files.py b/src/bin/pegleg/tests/unit/test_engine_util_files.py
new file mode 100644
index 00000000..4f1451a8
--- /dev/null
+++ b/src/bin/pegleg/tests/unit/test_engine_util_files.py
@@ -0,0 +1,30 @@
+# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import tempfile
+
+from pegleg import config
+from pegleg.engine.util import files
+
+def test_no_non_yamls(tmpdir):
+    p = tmpdir.mkdir("site_yamls").mkdir("global")
+    for x in range(3):  # Create 3 YAML files
+        p.join("good-%d.yaml" % x).write('fake-content')
+    p.join("bad.txt").write("fake-content")
+    config.set_primary_repo(str(tmpdir.listdir()[0]))
+    results = list(files.all())
+
+    assert 3 == len(results)
+    # make sure only YAML files are returned
+    for i in results:
+        assert i.endswith('.yaml')
diff --git a/src/bin/pegleg/tests/unit/test_selectable_linitng.py b/src/bin/pegleg/tests/unit/test_selectable_linting.py
similarity index 100%
rename from src/bin/pegleg/tests/unit/test_selectable_linitng.py
rename to src/bin/pegleg/tests/unit/test_selectable_linting.py