feat(config): wire serial tool into runtime and dashboard
This commit is contained in:
1 parent
0f52076762
commit
2114e1a53f
8 files changed
+93
No files matched your search
@@ -92,9 +92,36 @@ func TestHandleListTools(t *testing.T) {
|
||||
if gotTools["i2c"].Status != "disabled" {
|
||||
t.Fatalf("i2c status = %q, want disabled on linux when config is off", gotTools["i2c"].Status)
|
||||
}
|
||||
if gotTools["serial"].Status != "disabled" {
|
||||
t.Fatalf("serial status = %q, want disabled when config is off", gotTools["serial"].Status)
|
||||
}
|
||||
|
||||
cfg.Tools.Serial.Enabled = true
|
||||
if err := config.SaveConfig(configPath, cfg); err != nil {
|
||||
t.Fatalf("SaveConfig() error = %v", err)
|
||||
}
|
||||
|
||||
rec = httptest.NewRecorder()
|
||||
req = httptest.NewRequest(http.MethodGet, "/api/tools", nil)
|
||||
mux.ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, want %d, body=%s", rec.Code, http.StatusOK, rec.Body.String())
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
|
||||
t.Fatalf("Unmarshal() error = %v", err)
|
||||
}
|
||||
gotTools = make(map[string]toolSupportItem, len(resp.Tools))
|
||||
for _, tool := range resp.Tools {
|
||||
gotTools[tool.Name] = tool
|
||||
}
|
||||
if gotTools["serial"].Status != "enabled" {
|
||||
t.Fatalf("serial = %#v, want enabled on linux when config is on", gotTools["serial"])
|
||||
}
|
||||
} else {
|
||||
cfg.Tools.I2C.Enabled = true
|
||||
cfg.Tools.SPI.Enabled = true
|
||||
cfg.Tools.Serial.Enabled = true
|
||||
if err := config.SaveConfig(configPath, cfg); err != nil {
|
||||
t.Fatalf("SaveConfig() error = %v", err)
|
||||
}
|
||||
@@ -120,6 +147,16 @@ func TestHandleListTools(t *testing.T) {
|
||||
if gotTools["spi"].Status != "blocked" || gotTools["spi"].ReasonCode != "requires_linux" {
|
||||
t.Fatalf("spi = %#v, want blocked/requires_linux", gotTools["spi"])
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case "darwin", "windows":
|
||||
if gotTools["serial"].Status != "enabled" {
|
||||
t.Fatalf("serial = %#v, want enabled on supported host", gotTools["serial"])
|
||||
}
|
||||
default:
|
||||
if gotTools["serial"].Status != "blocked" || gotTools["serial"].ReasonCode != "requires_serial_platform" {
|
||||
t.Fatalf("serial = %#v, want blocked/requires_serial_platform", gotTools["serial"])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,6 +232,26 @@ func TestHandleUpdateToolState(t *testing.T) {
|
||||
if !updated.Tools.Cron.Enabled {
|
||||
t.Fatalf("cron should be enabled: %#v", updated.Tools.Cron)
|
||||
}
|
||||
|
||||
rec4 := httptest.NewRecorder()
|
||||
req4 := httptest.NewRequest(
|
||||
http.MethodPut,
|
||||
"/api/tools/serial/state",
|
||||
bytes.NewBufferString(`{"enabled":true}`),
|
||||
)
|
||||
req4.Header.Set("Content-Type", "application/json")
|
||||
mux.ServeHTTP(rec4, req4)
|
||||
if rec4.Code != http.StatusOK {
|
||||
t.Fatalf("serial status = %d, want %d, body=%s", rec4.Code, http.StatusOK, rec4.Body.String())
|
||||
}
|
||||
|
||||
updated, err = config.LoadConfig(configPath)
|
||||
if err != nil {
|
||||
t.Fatalf("LoadConfig(updated serial) error = %v", err)
|
||||
}
|
||||
if !updated.Tools.Serial.Enabled {
|
||||
t.Fatalf("serial should be enabled: %#v", updated.Tools.Serial)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleListTools_ReportsWebSearchEnabledWhenToolIsOn(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user