2026-07-18 15:59:57 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"errors"
|
|
|
|
|
"os"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestConfigCommandsDoNotResolveRunState(t *testing.T) {
|
|
|
|
|
for _, args := range [][]string{
|
|
|
|
|
{"config", "validate", "--config"},
|
|
|
|
|
{"pipelines", "list", "--config"},
|
|
|
|
|
} {
|
|
|
|
|
name := strings.Join(args[:2], "-")
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
|
roots := newStateTestRoots(t)
|
|
|
|
|
opts := newStateTestHarness().options()
|
|
|
|
|
opts.UserCacheDir = func() (string, error) { return "", errors.New("state root must not be resolved") }
|
|
|
|
|
command := append([]string(nil), args...)
|
|
|
|
|
command = append(command, roots.config)
|
|
|
|
|
var stdout, stderr bytes.Buffer
|
|
|
|
|
code := RunWithOptions(command, &stdout, &stderr, opts)
|
|
|
|
|
if code != 0 {
|
|
|
|
|
t.Fatalf("code=%d stdout=%q stderr=%q", code, stdout.String(), stderr.String())
|
|
|
|
|
}
|
|
|
|
|
assertNoRunState(t, roots)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func replaceStateTestConfigLine(t *testing.T, path, old, new string) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
data, err := os.ReadFile(path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2026-07-18 12:14:46 -05:00
|
|
|
text := replaceRequiredOnce(t, string(data), old, new)
|
2026-07-18 15:59:57 +00:00
|
|
|
if err := os.WriteFile(path, []byte(text), 0o600); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func removeStateTestConfigLine(t *testing.T, path, line string) {
|
|
|
|
|
replaceStateTestConfigLine(t, path, line, "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func assertNoRunState(t *testing.T, roots stateTestRoots) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
assertAbsent(t, roots.output)
|
|
|
|
|
assertAbsent(t, roots.plans)
|
|
|
|
|
assertAbsent(t, roots.checkpoints)
|
|
|
|
|
assertAbsent(t, roots.debug)
|
|
|
|
|
}
|