feat: initialize managed portal
This commit is contained in:
101
internal/managed/registry_test.go
Normal file
101
internal/managed/registry_test.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package managed
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoadRegistry(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
root := t.TempDir()
|
||||
registryPath := filepath.Join(root, "managed_services.yaml")
|
||||
writeFile(t, registryPath, `
|
||||
services:
|
||||
- id: store_dwell_alert
|
||||
display_name: Store Dwell Alert
|
||||
project_type: store_dwell_alert
|
||||
project_root: ./store_dwell_alert
|
||||
container_name: store-dwell-alert
|
||||
api_base_url: http://store-dwell-alert:18081
|
||||
config_path: ./configs/store.yaml
|
||||
result_type: store_dwell_alert
|
||||
- id: people_flow_project
|
||||
display_name: People Flow Project
|
||||
project_type: people_flow_project
|
||||
project_root: ./people_flow_project
|
||||
container_name: people-flow-project
|
||||
api_base_url: http://people-flow-project:18082
|
||||
result_type: people_flow_project
|
||||
`)
|
||||
|
||||
registry, err := LoadRegistry(registryPath)
|
||||
if err != nil {
|
||||
t.Fatalf("LoadRegistry() error = %v", err)
|
||||
}
|
||||
|
||||
if len(registry.Services) != 2 {
|
||||
t.Fatalf("len(Services) = %d, want 2", len(registry.Services))
|
||||
}
|
||||
|
||||
store := registry.Services[0]
|
||||
if store.ID != "store_dwell_alert" {
|
||||
t.Fatalf("store.ID = %q", store.ID)
|
||||
}
|
||||
if store.ProjectRoot != filepath.Join(root, "store_dwell_alert") {
|
||||
t.Fatalf("store.ProjectRoot = %q", store.ProjectRoot)
|
||||
}
|
||||
if store.ConfigPath != filepath.Join(root, "configs", "store.yaml") {
|
||||
t.Fatalf("store.ConfigPath = %q", store.ConfigPath)
|
||||
}
|
||||
if store.ServiceName != "store-dwell-alert" {
|
||||
t.Fatalf("store.ServiceName = %q", store.ServiceName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRegistryRejectsDuplicateIDs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
root := t.TempDir()
|
||||
registryPath := filepath.Join(root, "managed_services.yaml")
|
||||
writeFile(t, registryPath, `
|
||||
services:
|
||||
- id: repeated
|
||||
display_name: One
|
||||
project_type: store
|
||||
project_root: ./one
|
||||
container_name: one
|
||||
api_base_url: http://one
|
||||
result_type: store
|
||||
- id: repeated
|
||||
display_name: Two
|
||||
project_type: people
|
||||
project_root: ./two
|
||||
container_name: two
|
||||
api_base_url: http://two
|
||||
result_type: people
|
||||
`)
|
||||
|
||||
_, err := LoadRegistry(registryPath)
|
||||
if err == nil || !strings.Contains(err.Error(), `duplicate service id "repeated"`) {
|
||||
t.Fatalf("LoadRegistry() error = %v, want duplicate id", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRegistryRejectsMissingRequiredFields(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
root := t.TempDir()
|
||||
registryPath := filepath.Join(root, "managed_services.yaml")
|
||||
writeFile(t, registryPath, `
|
||||
services:
|
||||
- id: missing_fields
|
||||
display_name: Missing Fields
|
||||
`)
|
||||
|
||||
_, err := LoadRegistry(registryPath)
|
||||
if err == nil || !strings.Contains(err.Error(), "project_type is required") {
|
||||
t.Fatalf("LoadRegistry() error = %v, want missing field error", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user