Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

progress: look at stdout rather than stdin when choosing a suitable meter #15038

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func MockMeter(meter Meter) func() {
var inTesting bool = (osutil.IsTestBinary()) || os.Getenv("SPREAD_SYSTEM") != ""

var isTerminal = func() bool {
return !inTesting && terminal.IsTerminal(int(os.Stdin.Fd()))
return !inTesting && terminal.IsTerminal(int(os.Stdout.Fd()))
}

// MakeProgressBar creates an appropriate progress.Meter for the environ in
Expand Down
35 changes: 35 additions & 0 deletions tests/main/progress/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
summary: Verify progress reporting from snap command

description: |
Verify that progress reporting from snap command works as expected depending
on whether the command is ran with a tty attached or not.

systems: [-ubuntu-core-*]

prepare: |
tests.pkgs install socat

exec: |
echo "Minimal status reported when stdout is redirected"
# no stdin, stdout to a pipe
snap install test-snapd-tools-core24 </dev/null | tee -a non-tty-install.log
snap remove test-snapd-tools-core24 </dev/null | tee -a non-tty-remove.log
# a single summary line for both operations
test "$(wc -l non-tty-install.log)" = "1"
MATCH "test-snapd-tools-core24 .* installed" < non-tty-install.log
test "$(wc -l non-tty-remove.log)" = "1"
MATCH "test-snapd-tools-core24 .* removed" < non-tty-remove.log

echo "Rich status reporting when stdout is on a tty"
socat system:'snap install test-snapd-tools-core24',pyt,raw,echo=0 - | tr '\r' '\n' > tty-install.log
socat system:'snap remove test-snapd-tools-core24',pyt,raw,echo=0 - | tr '\r' '\n' > tty-remove.log
# more than one line for each operation
test "$(wc -l tty-install.log)" -gt "1"
test "$(wc -l tty-remove.log)" -gt "1"
# multiple status messages and a summary
MATCH "Fetch and check assertions for snap" < tty-install.log
MATCH "Mount snap" < tty-install.log
MATCH "test-snapd-tools-core24 .* installed" < tty-install.log

MATCH "Remove snap" < tty-remove.log
MATCH "test-snapd-tools-core24 .* removed" < tty-remove.log
Loading