mirror of
https://github.com/fosrl/newt.git
synced 2026-04-10 11:56:37 +00:00
Treat an empty CONFIG_FILE as initial state instead of failing JSON parse, so provisioning can proceed and credentials can be saved. Ref: fosrl/pangolin#2812
36 lines
757 B
Go
36 lines
757 B
Go
package websocket
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadConfig_EmptyFileMarksConfigForSave(t *testing.T) {
|
|
t.Setenv("CONFIG_FILE", "")
|
|
|
|
tmpDir := t.TempDir()
|
|
configPath := filepath.Join(tmpDir, "config.json")
|
|
if err := os.WriteFile(configPath, []byte(""), 0o644); err != nil {
|
|
t.Fatalf("failed to create empty config file: %v", err)
|
|
}
|
|
|
|
client := &Client{
|
|
config: &Config{
|
|
Endpoint: "https://example.com",
|
|
ProvisioningKey: "spk-test",
|
|
},
|
|
clientType: "newt",
|
|
configFilePath: configPath,
|
|
}
|
|
|
|
if err := client.loadConfig(); err != nil {
|
|
t.Fatalf("loadConfig returned error for empty file: %v", err)
|
|
}
|
|
|
|
if !client.configNeedsSave {
|
|
t.Fatal("expected empty config file to mark configNeedsSave")
|
|
}
|
|
}
|
|
|