Files
BrowserOS/packages/browseros/tools/patch/cmd/common_test.go
Nikhil e7105ae50b fix: improve browseros-patch workspace feedback (#921)
* fix: make patch list registry-only

* feat: add patch command progress logs

* fix: address review feedback for PR #921
2026-05-02 15:09:31 -07:00

44 lines
881 B
Go

package cmd
import (
"bytes"
"strings"
"testing"
"github.com/spf13/cobra"
)
func TestCommandProgressWritesHumanUpdatesToStderr(t *testing.T) {
oldJSONOut := jsonOut
t.Cleanup(func() {
jsonOut = oldJSONOut
})
jsonOut = false
var stderr bytes.Buffer
cmd := &cobra.Command{}
cmd.SetErr(&stderr)
progress := commandProgress(cmd)
if progress == nil {
t.Fatalf("expected human progress reporter")
}
progress.Step("Applying 1 patch operation")
if !strings.Contains(stderr.String(), "Applying 1 patch operation") {
t.Fatalf("expected progress on stderr, got %q", stderr.String())
}
}
func TestCommandProgressDisabledForJSON(t *testing.T) {
oldJSONOut := jsonOut
t.Cleanup(func() {
jsonOut = oldJSONOut
})
jsonOut = true
if progress := commandProgress(&cobra.Command{}); progress != nil {
t.Fatalf("expected nil progress reporter in JSON mode")
}
}