You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2018/11/30 16:38:41 UTC

[trafficcontrol] branch master updated: v3.1.0 - now properly ignores lua comment headers in plaintext files (#3064)

This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 1218855  v3.1.0 - now properly ignores lua comment headers in plaintext files (#3064)
1218855 is described below

commit 121885595a579edf3036397292e48e8785926c23
Author: ocket8888 <oc...@gmail.com>
AuthorDate: Fri Nov 30 09:38:36 2018 -0700

    v3.1.0 - now properly ignores lua comment headers in plaintext files (#3064)
---
 traffic_ops/testing/compare/compare.go | 54 +++++++++++++++++-----------------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/traffic_ops/testing/compare/compare.go b/traffic_ops/testing/compare/compare.go
index 3274fd7..220d773 100644
--- a/traffic_ops/testing/compare/compare.go
+++ b/traffic_ops/testing/compare/compare.go
@@ -36,9 +36,10 @@ import (
 	"golang.org/x/net/publicsuffix"
 )
 
-const __version__ = "3.0.0"
+const __version__ = "3.1.0"
 const SHORT_HEADER = "# DO NOT EDIT"
 const LONG_HEADER = "# TRAFFIC OPS NOTE:"
+const LUA_HEADER = "-- DO NOT EDIT"
 const MAX_RETRIES = 5
 
 // Environment variables used:
@@ -196,6 +197,29 @@ func readRespBodies(a *io.ReadCloser, b *io.ReadCloser) ([]byte, []byte, error)
 	return aBody, bBody, nil
 }
 
+// Scrubs out the traffic ops headers from the passed lines
+// Note that this assumes UNIX line endings
+func scrubPlainText(lines []string) string {
+	r := ""
+	for _, l := range lines {
+		if len(l) >= len(SHORT_HEADER) && l[:len(SHORT_HEADER)] == SHORT_HEADER {
+			continue
+		}
+
+		if len(l) >= len(LUA_HEADER) && l[:len(LUA_HEADER)] == LUA_HEADER {
+			continue
+		}
+
+		if len(l) >= len(LONG_HEADER) && l[:len(LONG_HEADER)] == LONG_HEADER {
+			continue
+		}
+
+		r += l
+	}
+
+	return r
+}
+
 // Given a slice of (exactly two) result objects, compares the plain text content of their responses
 // and write them to files if they differ. Ignores Traffic Ops headers in the response (to the
 // degree possible)
@@ -220,33 +244,9 @@ func handlePlainTextResponse(responses *[]result, route string) {
 			return
 		}
 
-		for _, line := range lines0 {
-			if len(line) < len(SHORT_HEADER) {
-				scrubbedResult0 += line
-			} else if line[:len(SHORT_HEADER)] != SHORT_HEADER {
-				if len(line) >= len(LONG_HEADER) {
-					if line[:len(LONG_HEADER)] != LONG_HEADER {
-						scrubbedResult0 += line
-					}
-				} else {
-					scrubbedResult0 += line
-				}
-			}
-		}
+		scrubbedResult0 = scrubPlainText(lines0)
+		scrubbedResult1 = scrubPlainText(lines1)
 
-		for _, line := range lines1 {
-			if len(line) < len(SHORT_HEADER) {
-				scrubbedResult1 += line
-			} else if line[:len(SHORT_HEADER)] != SHORT_HEADER {
-				if len(line) >= len(LONG_HEADER) {
-					if line[:len(LONG_HEADER)] != LONG_HEADER {
-						scrubbedResult1 += line
-					}
-				} else {
-					scrubbedResult1 += line
-				}
-			}
-		}
 	} else {
 		scrubbedResult0 = result0Str
 		scrubbedResult1 = result1Str