[master] 2ac661197 vtc: Add varnishadm pass/script/interactive coverage

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Sep 20 05:50:10 UTC 2021


commit 2ac661197a84c4ae0242e3a277a659f50dc9cec1
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Mon Sep 20 07:36:41 2021 +0200

    vtc: Add varnishadm pass/script/interactive coverage
    
    To avoid trailing blanks in diffs I decided to use underscores.
    
    In curses test cases, pack process writes with the following
    expectations.
    
    Refs #3691

diff --git a/bin/varnishtest/tests/u00001.vtc b/bin/varnishtest/tests/u00001.vtc
new file mode 100644
index 000000000..d2e7e34ab
--- /dev/null
+++ b/bin/varnishtest/tests/u00001.vtc
@@ -0,0 +1,62 @@
+varnishtest "trivial run of varnishadm in script mode"
+
+feature cmd "python3 -c 'import json'"
+
+varnish v1 -vcl {backend be none;} -start
+
+shell {
+	cat >expected.txt <<-EOF
+	Child_in_state_running
+	EOF
+	varnishadm -n ${v1_name} status | tr ' ' _ >actual.txt
+	diff -u expected.txt actual.txt
+}
+
+# same command via stdin
+shell {
+	echo status | varnishadm -n ${v1_name} | tr ' ' _ >actual.txt
+	diff -u expected.txt actual.txt
+}
+
+shell {
+	cat >expected.txt <<-EOF
+	200_22______
+	Child_in_state_running
+	EOF
+	{
+		varnishadm -n ${v1_name} -p status
+		printf '\n' # easier to add here than remove in expected.txt
+	} | tr ' ' _ >actual.txt
+	diff -u expected.txt actual.txt
+}
+
+# same command via stdin
+shell {
+	echo status | varnishadm -n ${v1_name} -p | tr ' ' _ >actual.txt
+	printf '\n' >>actual.txt
+	diff -u expected.txt actual.txt
+}
+
+shell {
+	varnishadm -n ${v1_name} status -j |
+	python3 -c 'import sys, json; print(json.load(sys.stdin))'
+}
+
+# same command via stdin
+shell {
+	echo 'status -j' |
+	varnishadm -n ${v1_name} |
+	python3 -c 'import sys, json; print(json.load(sys.stdin))'
+}
+
+shell -err {
+	varnishadm -n ${v1_name} -p status -j |
+	python3 -c 'import sys, json; print(json.load(sys.stdin))'
+}
+
+# same command via stdin
+shell -err {
+	echo 'status -j' |
+	varnishadm -n ${v1_name} -p |
+	python3 -c 'import sys, json; print(json.load(sys.stdin))'
+}
diff --git a/bin/varnishtest/tests/u00011.vtc b/bin/varnishtest/tests/u00011.vtc
index 439fbfafc..1561ad1e4 100644
--- a/bin/varnishtest/tests/u00011.vtc
+++ b/bin/varnishtest/tests/u00011.vtc
@@ -18,16 +18,15 @@ process p1 -log {varnishadm -n ${v1_name}} -start
 
 process p1 -expect-text 0 1 "Type 'quit' to close CLI session."
 
+# expect a status in interactive mode (after a banner)
 process p1 -write "pin\t\r"
-
-process p1 -expect-text 0 1 "PONG"
+process p1 -expect-text 12 1 "200         "
+process p1 -expect-text 13 1 PONG
 
 process p1 -write "vcl.li\t\r"
-
 process p1 -expect-text 0 1 "active   auto    warm"
 
 process p1 -write "vcl.s\t\th\t vcl1\r"
-
 process p1 -expect-text 0 1 "backend s1"
 
 process p1 -screen_dump -write "quit\r" -wait
diff --git a/bin/varnishtest/tests/u00012.vtc b/bin/varnishtest/tests/u00012.vtc
index 5dc3fcb9e..6c5af113f 100644
--- a/bin/varnishtest/tests/u00012.vtc
+++ b/bin/varnishtest/tests/u00012.vtc
@@ -16,18 +16,15 @@ varnish v1 -vsl_catchup
 
 process p1 -log {varnishadm -p -n ${v1_name}} -start
 
+# expect a full status line in pass mode (no banner)
 process p1 -write "ping\r"
-
-process p1 -expect-text 0 1 "200 19"
-
-process p1 -expect-text 0 1 "PONG"
+process p1 -expect-text 2 1 "200 19      "
+process p1 -expect-text 3 1 PONG
 
 process p1 -write "vcl.list\r"
-
 process p1 -expect-text 0 0 "auto    warm" 
 
 process p1 -write "vcl.show vcl1\r"
-
 process p1 -expect-text 0 0 "backend s1"
 
 process p1 -screen_dump -write "\x04" -wait


More information about the varnish-commit mailing list