Files
bd2/go/internal/server/gameconfig/config_test.go
T
Flechazo 5d86657c75 feat: add game SDK and harden client login and game rules
- Add costume burst upgrades with durable replay and fix permanent SR equipment gacha.
- Add server game.json rules for optional collaboration UR weapons, with packaging and documentation.
- Add GameNames/GameSdk NuGet tooling, readable types, reobfuscation, complete source/PDB navigation and shared-runtime installation.
- Split plugin responsibilities, prefer typeof/nameof, centralize MSBuild settings and ignore local paths; remove the unused LoginUI test project.
- Fix login recovery and TLS through native platform HTTP and a private game relay; read device region directly from the OS time zone.

Validation: go test ./... -count=1, go vet ./..., plugin Release builds, SDK/runtime self-tests, Roslyn embedded-source navigation, gofmt check and git diff --check.
2026-10-03 23:04:32 +08:00

77 lines
2.5 KiB
Go

package gameconfig
import (
"os"
"path/filepath"
"testing"
)
func TestLoad(t *testing.T) {
for _, tc := range []struct {
name, text string
wantTrue, wantError bool
}{
{"enabled", `{"schema_version":1,"gacha":{"include_collaboration_ur_weapons":true}}`, true, false},
{"disabled", `{"schema_version":1,"gacha":{"include_collaboration_ur_weapons":false}}`, false, false},
{"omitted bool", `{"schema_version":1,"gacha":{}}`, false, false},
{"omitted gacha", `{"schema_version":1}`, false, false},
{"string bool", `{"schema_version":1,"gacha":{"include_collaboration_ur_weapons":"true"}}`, false, true},
{"unknown root", `{"schema_version":1,"unknown":true}`, false, true},
{"unknown rule", `{"schema_version":1,"gacha":{"typo":true}}`, false, true},
{"trailing object", `{"schema_version":1} {}`, false, true},
{"trailing garbage", `{"schema_version":1} invalid`, false, true},
{"null root", `null`, false, true},
{"null section", `{"schema_version":1,"gacha":null}`, false, true},
{"null bool", `{"schema_version":1,"gacha":{"include_collaboration_ur_weapons":null}}`, false, true},
{"null schema", `{"schema_version":null}`, false, true},
{"wrong version", `{"schema_version":2}`, false, true},
{"missing version", `{}`, false, true},
{"malformed", `{`, false, true},
} {
t.Run(tc.name, func(t *testing.T) {
path := filepath.Join(t.TempDir(), FileName)
if err := os.WriteFile(path, []byte(tc.text), 0600); err != nil {
t.Fatal(err)
}
cfg, err := Load(path)
if (err != nil) != tc.wantError {
t.Fatalf("Load error = %v, wantError %v", err, tc.wantError)
}
if err == nil && (cfg.SchemaVersion != 1 || cfg.Gacha.IncludeCollaborationURWeapons != tc.wantTrue) {
t.Fatalf("unexpected config: %+v", cfg)
}
})
}
}
func TestMissingFileDefaultsWithoutCreating(t *testing.T) {
path := filepath.Join(t.TempDir(), FileName)
cfg, err := Load(path)
if err != nil || cfg != Default() {
t.Fatalf("config = %+v, error = %v", cfg, err)
}
if _, err := os.Stat(path); !os.IsNotExist(err) {
t.Fatalf("Load created missing config: %v", err)
}
}
func TestReadError(t *testing.T) {
if _, err := Load(t.TempDir()); err == nil {
t.Fatal("directory must not use defaults")
}
}
func TestBesideExecutable(t *testing.T) {
path, err := BesideExecutable()
if err != nil {
t.Fatal(err)
}
executable, err := os.Executable()
if err != nil {
t.Fatal(err)
}
if path != filepath.Join(filepath.Dir(executable), FileName) {
t.Fatalf("unexpected path %s", path)
}
}