services -> domains

This commit is contained in:
2026-07-10 20:46:22 +00:00
parent 3c99d26830
commit 79c0c32b98
45 changed files with 1447 additions and 1270 deletions

View File

@@ -13,7 +13,7 @@ import (
"gopkg.in/yaml.v3"
)
func TestGetGlobalConfig_ReturnsWrappedResponse(t *testing.T) {
func TestGetState_ReturnsWrappedResponse(t *testing.T) {
api, tmpDir := setupTestAPI(t)
// Write a config with a central domain
@@ -30,10 +30,10 @@ func TestGetGlobalConfig_ReturnsWrappedResponse(t *testing.T) {
data, _ := yaml.Marshal(cfg)
storage.WriteFile(filepath.Join(tmpDir, "state.yaml"), data, 0644)
req := httptest.NewRequest("GET", "/api/v1/config", nil)
req := httptest.NewRequest("GET", "/api/v1/state", nil)
w := httptest.NewRecorder()
api.GetGlobalConfig(w, req)
api.GetState(w, req)
if w.Code != http.StatusOK {
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
@@ -42,33 +42,33 @@ func TestGetGlobalConfig_ReturnsWrappedResponse(t *testing.T) {
var resp map[string]any
json.Unmarshal(w.Body.Bytes(), &resp)
// Must have "configured" and "config" keys
// Must have "configured" and "state" keys
if resp["configured"] != true {
t.Errorf("expected configured=true, got %v", resp["configured"])
}
config, ok := resp["config"].(map[string]any)
state, ok := resp["state"].(map[string]any)
if !ok {
t.Fatalf("expected config to be a map, got %T", resp["config"])
t.Fatalf("expected state to be a map, got %T", resp["state"])
}
// Verify nested structure is preserved
cloud, _ := config["cloud"].(map[string]any)
cloud, _ := state["cloud"].(map[string]any)
central, _ := cloud["central"].(map[string]any)
if central["domain"] != "central.example.com" {
t.Errorf("expected domain central.example.com, got %v", central["domain"])
}
}
func TestGetGlobalConfig_EmptyReturnsNotConfigured(t *testing.T) {
func TestGetState_EmptyReturnsNotConfigured(t *testing.T) {
api, tmpDir := setupTestAPI(t)
// Ensure no state file exists
os.Remove(filepath.Join(tmpDir, "state.yaml"))
req := httptest.NewRequest("GET", "/api/v1/config", nil)
req := httptest.NewRequest("GET", "/api/v1/state", nil)
w := httptest.NewRecorder()
api.GetGlobalConfig(w, req)
api.GetState(w, req)
if w.Code != http.StatusOK {
t.Fatalf("expected 200, got %d", w.Code)
@@ -146,7 +146,7 @@ func TestGetGlobalSecrets_RawShowsValues(t *testing.T) {
}
}
func TestUpdateGlobalConfig(t *testing.T) {
func TestUpdateState(t *testing.T) {
api, tmpDir := setupTestAPI(t)
update := map[string]any{
@@ -158,10 +158,10 @@ func TestUpdateGlobalConfig(t *testing.T) {
}
body, _ := json.Marshal(update)
req := httptest.NewRequest("PUT", "/api/v1/config", bytes.NewReader(body))
req := httptest.NewRequest("PUT", "/api/v1/state", bytes.NewReader(body))
w := httptest.NewRecorder()
api.UpdateGlobalConfig(w, req)
api.UpdateState(w, req)
if w.Code != http.StatusOK {
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())