-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_test.go
More file actions
45 lines (41 loc) · 1.16 KB
/
Copy pathconfig_test.go
File metadata and controls
45 lines (41 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"encoding/json"
"os"
"path/filepath"
"testing"
)
func TestSaveControlConfigWritesState(t *testing.T) {
t.Setenv("CODEX_STATE_DIR", t.TempDir())
t.Setenv("USERNAME", "AIGCFREE")
config, err := saveControlConfig(map[string]any{
"port": "8787",
"relayUrl": "https://codexpanel-wan.pages.dev",
"remoteKey": "BFRPWRY",
})
if err != nil {
t.Fatal(err)
}
if config["relayUrl"] != "https://codexpanel-wan.pages.dev" {
t.Fatalf("unexpected relayUrl: %v", config["relayUrl"])
}
if config["remoteKey"] != "BFRPWRY" {
t.Fatalf("unexpected remoteKey: %v", config["remoteKey"])
}
data, err := os.ReadFile(filepath.Join(os.Getenv("CODEX_STATE_DIR"), "state.json"))
if err != nil {
t.Fatal(err)
}
var state struct {
ControlConfig map[string]any `json:"controlConfig"`
}
if err := json.Unmarshal(data, &state); err != nil {
t.Fatal(err)
}
if state.ControlConfig["relayUrl"] != "https://codexpanel-wan.pages.dev" {
t.Fatalf("state relayUrl was not saved: %v", state.ControlConfig["relayUrl"])
}
if state.ControlConfig["remoteKey"] != "BFRPWRY" {
t.Fatalf("state remoteKey was not saved: %v", state.ControlConfig["remoteKey"])
}
}