From 7bf940be0a76fd71b846604d826b4e90c00bb292 Mon Sep 17 00:00:00 2001
From: Pim van Pelt <pim@ipng.nl>
Date: Tue, 22 Mar 2022 15:10:40 +0000
Subject: [PATCH] Become a bit stricter: do full-line pattern match, and update
 unit tests to capture the full error output

---
 tests.py                                | 2 +-
 unittest/yaml/error-interface-mtu1.yaml | 4 ++--
 unittest/yaml/error-schema-field1.yaml  | 2 +-
 unittest/yaml/error-schema-field2.yaml  | 2 +-
 unittest/yaml/error-subinterface1.yaml  | 4 ++--
 unittest/yaml/error-subinterface6.yaml  | 2 +-
 6 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/tests.py b/tests.py
index 9b0d675..e2d3ba5 100755
--- a/tests.py
+++ b/tests.py
@@ -68,7 +68,7 @@ class YAMLTest(unittest.TestCase):
         for m in msgs:
             this_msg_expected = False
             for expected in msgs_expected:
-                if re.search(expected, m):
+                if re.match(expected, m):
                     this_msg_expected = True
                     break
             if not this_msg_expected:
diff --git a/unittest/yaml/error-interface-mtu1.yaml b/unittest/yaml/error-interface-mtu1.yaml
index 62b4ec6..d6b966c 100644
--- a/unittest/yaml/error-interface-mtu1.yaml
+++ b/unittest/yaml/error-interface-mtu1.yaml
@@ -2,8 +2,8 @@ test:
   description: "MTU too small on one interface, too large on another"
   errors:
     expected: 
-     - "mtu.*less than 128"
-     - "mtu.*greater than 9216"
+     - "yamale:.*mtu: 127 is less than 128"
+     - "yamale:.*mtu: 9217 is greater than 9216"
     count: 2
 ---
 interfaces:
diff --git a/unittest/yaml/error-schema-field1.yaml b/unittest/yaml/error-schema-field1.yaml
index c54ba72..112a1dc 100644
--- a/unittest/yaml/error-schema-field1.yaml
+++ b/unittest/yaml/error-schema-field1.yaml
@@ -2,7 +2,7 @@ test:
   description: "Interface description field mistyped"
   errors:
     expected: 
-     - "descr.*Unexpected element"
+     - "yamale:.*descr: Unexpected element"
     count: 1
 ---
 interfaces:
diff --git a/unittest/yaml/error-schema-field2.yaml b/unittest/yaml/error-schema-field2.yaml
index e774f70..52be219 100644
--- a/unittest/yaml/error-schema-field2.yaml
+++ b/unittest/yaml/error-schema-field2.yaml
@@ -4,7 +4,7 @@ test:
     expected:
      - "yamale: .* is not a "
      - "yamale: .*: Unexpected element"
-     - "Length of .* is greater than 15"
+     - "yamale: .*: Length of .* is greater than 15"
     count: 13
 ---
 interfaces:
diff --git a/unittest/yaml/error-subinterface1.yaml b/unittest/yaml/error-subinterface1.yaml
index ff2984f..4335ef0 100644
--- a/unittest/yaml/error-subinterface1.yaml
+++ b/unittest/yaml/error-subinterface1.yaml
@@ -2,8 +2,8 @@ test:
   description: "Two subinterfaces can't have the same encapsulation"
   errors:
     expected:
-     - "100 .* unique encapsulation"
-     - "101 .* unique encapsulation"
+     - "sub-interface .*.100 does not have unique encapsulation"
+     - "sub-interface .*.101 does not have unique encapsulation"
     count: 2
 ---
 interfaces:
diff --git a/unittest/yaml/error-subinterface6.yaml b/unittest/yaml/error-subinterface6.yaml
index f43158e..4373391 100644
--- a/unittest/yaml/error-subinterface6.yaml
+++ b/unittest/yaml/error-subinterface6.yaml
@@ -2,7 +2,7 @@ test:
   description: "A bunch of sub-interfaces with incorrect encapsulation"
   errors:
     expected:
-     - "has invalid encapsulation"
+     - "sub-interface .* has invalid encapsulation"
     count: 2
 ---
 interfaces: