vtest "trivial run of vinyladm in script mode"

feature cmd "command -v diff"
feature cmd "python3 -c 'import json'"

vinyl v1 -vcl {backend be none;} -start

shell {
	cat >expected.txt <<-EOF
	Child_in_state_running
	EOF
	vinyladm -n ${v1_name} status | tr ' ' _ >actual.txt
	diff -u expected.txt actual.txt
}

# same command via stdin
shell {
	echo status | vinyladm -n ${v1_name} | tr ' ' _ >actual.txt
	diff -u expected.txt actual.txt
}

shell {
	cat >expected.txt <<-EOF
	200_22______
	Child_in_state_running
	EOF
	{
		vinyladm -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 | vinyladm -n ${v1_name} -p | tr ' ' _ >actual.txt
	printf '\n' >>actual.txt
	diff -u expected.txt actual.txt
}

shell {
	vinyladm -n ${v1_name} status -j |
	python3 -c 'import sys, json; print(json.load(sys.stdin))'
}

# same command via stdin
shell {
	echo 'status -j' |
	vinyladm -n ${v1_name} |
	python3 -c 'import sys, json; print(json.load(sys.stdin))'
}

shell -err {
	vinyladm -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' |
	vinyladm -n ${v1_name} -p |
	python3 -c 'import sys, json; print(json.load(sys.stdin))'
}
