rdev/internal/service/component_test.go
jordan 1790afd0ee feat: add path-based ingress management for component lifecycle
Adds AddIngressPath and RemoveIngressPath to the Deployer interface
for managing per-component ingress rules in monorepo projects.

- Implement conflict retry logic for concurrent ingress updates
- Add K8s client interface for testability
- Add comprehensive unit tests for ingress path operations
- Add component deployment and teardown methods to ComponentService
- Update service templates with OpenAPI spec improvements
- Add evolving-app cookbook tree for reference
- Split resources.go into resources_ingress.go for path-based routing
- Split component.go into component_deploy.go for deployment helpers

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 01:31:50 -07:00

83 lines
1.6 KiB
Go

package service
import (
"testing"
"github.com/orchard9/rdev/internal/domain"
)
func TestAssignComponentPath(t *testing.T) {
tests := []struct {
name string
component *domain.Component
expectedPath string
}{
{
name: "service gets /api/{name}",
component: &domain.Component{
Type: domain.ComponentTypeService,
Name: "auth",
},
expectedPath: "/api/auth",
},
{
name: "service with different name",
component: &domain.Component{
Type: domain.ComponentTypeService,
Name: "users",
},
expectedPath: "/api/users",
},
{
name: "app-react gets /",
component: &domain.Component{
Type: domain.ComponentTypeAppReact,
Name: "web",
},
expectedPath: "/",
},
{
name: "app-astro gets /",
component: &domain.Component{
Type: domain.ComponentTypeAppAstro,
Name: "landing",
},
expectedPath: "/",
},
{
name: "app-nextjs gets /",
component: &domain.Component{
Type: domain.ComponentTypeAppNextJS,
Name: "dashboard",
},
expectedPath: "/",
},
{
name: "worker gets empty path",
component: &domain.Component{
Type: domain.ComponentTypeWorker,
Name: "processor",
},
expectedPath: "",
},
{
name: "cli gets empty path",
component: &domain.Component{
Type: domain.ComponentTypeCLI,
Name: "tool",
},
expectedPath: "",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
result := assignComponentPath(tc.component)
if result != tc.expectedPath {
t.Errorf("assignComponentPath(%s %s) = %q, want %q",
tc.component.Type, tc.component.Name, result, tc.expectedPath)
}
})
}
}