Files
dygou_go/internal/config/machine_remote_profile_test.go
T
yml d37fd50233 feat(remote): 支持单行连接与同机实例继承
- 远端地址和注册令牌合并为单行填写\n- 同机实例通过机器级配置继承远端连接\n- 实例令牌仍按实例独立保存
2026-11-21 22:01:33 +08:00

67 lines
1.7 KiB
Go

package config
import (
"os"
"path/filepath"
"testing"
"douyu_go/internal/types"
)
func TestMachineRemoteProfileIsInheritedByOtherInstances(t *testing.T) {
root := t.TempDir()
t.Setenv("DOUYU_DATA_DIR", root)
source := types.Config{
RemoteEnabled: true,
RemoteURL: " https://control.khhao.com ",
RemoteEnrollmentToken: " enroll-secret ",
RemoteMachineName: " PC-01 ",
}
if err := SaveMachineRemoteProfile(source); err != nil {
t.Fatal(err)
}
info, err := os.Stat(filepath.Join(root, "remote", machineRemoteProfileFile))
if err != nil {
t.Fatal(err)
}
if info.Mode().Perm() != 0600 {
t.Fatalf("profile mode=%o, want 600", info.Mode().Perm())
}
profile, ok, err := LoadMachineRemoteProfile()
if err != nil {
t.Fatal(err)
}
if !ok {
t.Fatal("machine remote profile should exist")
}
var inherited types.Config
ApplyMachineRemoteProfile(&inherited, profile)
if !inherited.RemoteEnabled ||
inherited.RemoteURL != "https://control.khhao.com" ||
inherited.RemoteEnrollmentToken != "enroll-secret" ||
inherited.RemoteMachineName != "PC-01" {
t.Fatalf("unexpected inherited remote config: %+v", inherited)
}
}
func TestMachineRemoteProfileCanDisableRemoteForNewInstances(t *testing.T) {
t.Setenv("DOUYU_DATA_DIR", t.TempDir())
if err := SaveMachineRemoteProfile(types.Config{
RemoteEnabled: false,
RemoteURL: "https://control.khhao.com",
}); err != nil {
t.Fatal(err)
}
profile, ok, err := LoadMachineRemoteProfile()
if err != nil || !ok {
t.Fatalf("LoadMachineRemoteProfile() ok=%v err=%v", ok, err)
}
cfg := types.Config{RemoteEnabled: true}
ApplyMachineRemoteProfile(&cfg, profile)
if cfg.RemoteEnabled {
t.Fatal("disabled machine profile should disable remote for new instances")
}
}