edge-connect-client/sdk/config/example_test.go
Waldemar 8b02fe54e5 feat(apply): Implement CLI command with comprehensive deployment workflow
- Add edge-connect apply command with -f/--file and --dry-run flags
- Integrate config parser, deployment planner, and resource manager
- Provide comprehensive error handling and progress reporting
- Support deployment confirmation prompts and result summaries
- Move internal packages to public SDK packages for CLI access
- Update all tests to pass with new package structure
- Complete Phase 4 CLI Command Implementation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-29 17:24:59 +02:00

130 lines
No EOL
3.9 KiB
Go

// ABOUTME: Integration test with the actual EdgeConnectConfig.yaml example file
// ABOUTME: Validates that our parser correctly handles the real example configuration
package config
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseExampleConfig(t *testing.T) {
parser := NewParser()
// Parse the actual example file (now that we've created the manifest file)
examplePath := filepath.Join("../examples/comprehensive/EdgeConnectConfig.yaml")
config, err := parser.ParseFile(examplePath)
// This should now succeed with full validation
require.NoError(t, err)
require.NotNil(t, config)
// Validate the parsed structure
assert.Equal(t, "edgeconnect-deployment", config.Kind)
assert.Equal(t, "edge-app-demo", config.Metadata.Name)
// Check k8s app configuration
require.NotNil(t, config.Spec.K8sApp)
assert.Equal(t, "edge-app-demo", config.Spec.K8sApp.AppName)
assert.Equal(t, "1.0.0", config.Spec.K8sApp.AppVersion)
// Note: ManifestFile path should be resolved to absolute path
assert.Contains(t, config.Spec.K8sApp.ManifestFile, "k8s-deployment.yaml")
// Check infrastructure template
require.Len(t, config.Spec.InfraTemplate, 1)
infra := config.Spec.InfraTemplate[0]
assert.Equal(t, "edp2", infra.Organization)
assert.Equal(t, "EU", infra.Region)
assert.Equal(t, "TelekomOP", infra.CloudletOrg)
assert.Equal(t, "Munich", infra.CloudletName)
assert.Equal(t, "EU.small", infra.FlavorName)
// Check network configuration
require.NotNil(t, config.Spec.Network)
require.Len(t, config.Spec.Network.OutboundConnections, 2)
conn1 := config.Spec.Network.OutboundConnections[0]
assert.Equal(t, "tcp", conn1.Protocol)
assert.Equal(t, 80, conn1.PortRangeMin)
assert.Equal(t, 80, conn1.PortRangeMax)
assert.Equal(t, "0.0.0.0/0", conn1.RemoteCIDR)
conn2 := config.Spec.Network.OutboundConnections[1]
assert.Equal(t, "tcp", conn2.Protocol)
assert.Equal(t, 443, conn2.PortRangeMin)
assert.Equal(t, 443, conn2.PortRangeMax)
assert.Equal(t, "0.0.0.0/0", conn2.RemoteCIDR)
// Test utility methods
assert.Equal(t, "edge-app-demo", config.Spec.GetAppName())
assert.Equal(t, "1.0.0", config.Spec.GetAppVersion())
assert.Contains(t, config.Spec.GetManifestFile(), "k8s-deployment.yaml")
assert.True(t, config.Spec.IsK8sApp())
assert.False(t, config.Spec.IsDockerApp())
// Test instance name generation
instanceName := GetInstanceName(config.Spec.GetAppName(), config.Spec.GetAppVersion())
assert.Equal(t, "edge-app-demo-1.0.0-instance", instanceName)
}
func TestValidateExampleStructure(t *testing.T) {
parser := &ConfigParser{}
// Create a config that matches the example but with valid paths
config := &EdgeConnectConfig{
Kind: "edgeconnect-deployment",
Metadata: Metadata{
Name: "edge-app-demo",
},
Spec: Spec{
DockerApp: &DockerApp{ // Use DockerApp to avoid manifest file validation
AppName: "edge-app-demo",
AppVersion: "1.0.0",
Image: "nginx:latest",
},
InfraTemplate: []InfraTemplate{
{
Organization: "edp2",
Region: "EU",
CloudletOrg: "TelekomOP",
CloudletName: "Munich",
FlavorName: "EU.small",
},
},
Network: &NetworkConfig{
OutboundConnections: []OutboundConnection{
{
Protocol: "tcp",
PortRangeMin: 80,
PortRangeMax: 80,
RemoteCIDR: "0.0.0.0/0",
},
{
Protocol: "tcp",
PortRangeMin: 443,
PortRangeMax: 443,
RemoteCIDR: "0.0.0.0/0",
},
},
},
},
}
// This should validate successfully
err := parser.Validate(config)
assert.NoError(t, err)
// Test comprehensive validation
err = parser.ComprehensiveValidate(config)
assert.NoError(t, err)
// Test infrastructure uniqueness validation
err = parser.ValidateInfrastructureUniqueness(config)
assert.NoError(t, err)
// Test port range validation
err = parser.ValidatePortRanges(config)
assert.NoError(t, err)
}