summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-05-27 23:22:25 -0400
committerBen Morrison <ben@gbmor.dev>2019-05-27 23:22:25 -0400
commit9d55d0b478f386aca48d8eeacbbfd4bd3b387bc0 (patch)
tree390f4cfc456baf633d40cd3f0e66fc27b13d769c
parent73f58c1e901082441b0ce9497b35cd9d80bd7f7d (diff)
downloadgetwtxt-9d55d0b478f386aca48d8eeacbbfd4bd3b387bc0.tar.gz
parseQueryOut() no longer adds newline to last element, test updated to account for this
-rw-r--r--query.go4
-rw-r--r--query_test.go6
2 files changed, 2 insertions, 8 deletions
diff --git a/query.go b/query.go
index e74e109..6b9792b 100644
--- a/query.go
+++ b/query.go
@@ -24,10 +24,10 @@ func apiErrCheck(err error, r *http.Request) {
 func parseQueryOut(out []string) []byte {
 	var data []byte
 
-	for _, e := range out {
+	for i, e := range out {
 		data = append(data, []byte(e)...)
 
-		if !strings.HasSuffix(e, "\n") {
+		if !strings.HasSuffix(e, "\n") && i != len(out)-1 {
 			data = append(data, byte('\n'))
 		}
 	}
diff --git a/query_test.go b/query_test.go
index 835ba90..28fb32d 100644
--- a/query_test.go
+++ b/query_test.go
@@ -40,12 +40,6 @@ func Test_parseQueryOut(t *testing.T) {
 
 		conv := strings.Split(string(out), "\n")
 
-		// It likes to append an empty element to the end.
-		// I need to fix that in the library.
-		if len(conv) > 0 && conv[len(conv)-1] == "" {
-			conv = conv[:len(conv)-1]
-		}
-
 		if !reflect.DeepEqual(data, conv) {
 			t.Errorf("Pre- and Post- parseQueryOut data are inequal:\n%#v\n%#v\n", data, conv)
 		}