mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-03 21:53:20 +09:00
For the commands this change touches (cozypkg list, the validation report of validate, push and tap, tap's summary, and check-readiness), a write error the process observes is a failure: the command exits non-zero and says whether the action it reports on already happened. Progress lines printed before the decisive step stay best-effort. A closed pipe ends the process with SIGPIPE, as for other Unix tools. `cozypkg list` and the validation report dropped write errors, and the list deferred its tabwriter flush, so a closed or full stdout still reported success with nothing printed. The list now writes to the command's writer and returns the flush error, and the report returns its write error. When validation refuses a push or a tap, or fails a validate run, the refusal stays the reported reason and the report's write error is joined to it. A push whose report cannot be written stops before flux runs and says "nothing was pushed"; a tap whose summary cannot be written fails with "tap applied, but writing its summary failed". check-readiness fails --help, --version and its readiness result the same way, in one-shot, --wait and --watch mode, with exit 1 as for a result that is not ready, which its help now lists among the exit statuses along with SIGPIPE for a closed pipe; the watch loop stops at the first frame it cannot write, and a timed-out wait still ends with its verdict. push writes its "Pushing" line before it runs flux and stops with "nothing was pushed" when that line cannot be written, with validation skipped or after the report. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <f@lex.la>
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
/*
|
|
Copyright 2026 The Cozystack Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestHelpAndVersionSucceedOnWritableStdout(t *testing.T) {
|
|
r, w, err := os.Pipe()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { _ = r.Close() })
|
|
stdout := os.Stdout
|
|
os.Stdout = w
|
|
t.Cleanup(func() { os.Stdout = stdout })
|
|
read := make(chan string, 1)
|
|
go func() {
|
|
b, _ := io.ReadAll(r)
|
|
read <- string(b)
|
|
}()
|
|
|
|
for _, arg := range []string{"--help", "--version"} {
|
|
if code := run([]string{arg}); code != 0 {
|
|
t.Errorf("run(%s) = %d, want 0", arg, code)
|
|
}
|
|
}
|
|
_ = w.Close()
|
|
if out := <-read; !strings.Contains(out, "Usage:") || !strings.Contains(out, Version) {
|
|
t.Errorf("stdout = %q, want the usage text and the version", out)
|
|
}
|
|
}
|
|
|
|
func TestHelpAndVersionFailOnUnwritableStdout(t *testing.T) {
|
|
r, w, err := os.Pipe()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_ = r.Close()
|
|
_ = w.Close()
|
|
stdout := os.Stdout
|
|
os.Stdout = w
|
|
t.Cleanup(func() { os.Stdout = stdout })
|
|
|
|
for _, arg := range []string{"--help", "--version"} {
|
|
if code := run([]string{arg}); code == 0 {
|
|
t.Errorf("run(%s) with an unwritable stdout = 0, want a failure", arg)
|
|
}
|
|
}
|
|
}
|