a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/zzet/gortex/internal/daemon"
|
|
)
|
|
|
|
// TestServerAdd_ReadOnlyPersisted asserts `daemon server add --read-only`
|
|
// writes read_only = true into the roster entry and that it reloads as a
|
|
// read-only remote.
|
|
func TestServerAdd_ReadOnlyPersisted(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "servers.toml")
|
|
t.Setenv("GORTEX_DAEMON_SERVERS", path)
|
|
|
|
// Drive the command's package-level flag vars directly.
|
|
daemonServerAddURL = "https://r2.example:4747"
|
|
daemonServerAddReadOnly = true
|
|
daemonServerAddDefault = false
|
|
daemonServerAddAuthToken = ""
|
|
daemonServerAddAuthTokenEnv = ""
|
|
daemonServerAddWorkspaces = nil
|
|
t.Cleanup(func() {
|
|
daemonServerAddURL = ""
|
|
daemonServerAddReadOnly = false
|
|
})
|
|
|
|
if err := runDaemonServerAdd(nil, []string{"r2"}); err != nil {
|
|
t.Fatalf("runDaemonServerAdd: %v", err)
|
|
}
|
|
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(string(data), "read_only = true") {
|
|
t.Fatalf("roster should carry read_only = true, got:\n%s", data)
|
|
}
|
|
|
|
cfg, err := daemon.LoadServersConfig(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(cfg.Server) != 1 || !cfg.Server[0].ReadOnly {
|
|
t.Fatalf("reloaded entry should be read-only, got %+v", cfg.Server)
|
|
}
|
|
}
|