mirror of
https://github.com/DeBrosOfficial/network.git
synced 2026-01-30 20:03:03 +00:00
fixed test issues
This commit is contained in:
parent
edd9c1f3dc
commit
7ded21939b
@ -8,6 +8,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -262,7 +263,7 @@ func TestDomainRouting_SPAFallback(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TestDeployment_DomainFormat verifies that deployment URLs use the correct format:
|
// TestDeployment_DomainFormat verifies that deployment URLs use the correct format:
|
||||||
// - CORRECT: {name}.{baseDomain} (e.g., "myapp.dbrs.space")
|
// - CORRECT: {name}-{random}.{baseDomain} (e.g., "myapp-f3o4if.dbrs.space")
|
||||||
// - WRONG: {name}.node-{shortID}.{baseDomain} (should NOT exist)
|
// - WRONG: {name}.node-{shortID}.{baseDomain} (should NOT exist)
|
||||||
func TestDeployment_DomainFormat(t *testing.T) {
|
func TestDeployment_DomainFormat(t *testing.T) {
|
||||||
env, err := LoadTestEnv()
|
env, err := LoadTestEnv()
|
||||||
@ -293,8 +294,9 @@ func TestDeployment_DomainFormat(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedDomain := env.BuildDeploymentDomain(deploymentName)
|
// Get the subdomain from deployment response
|
||||||
t.Logf("Expected domain format: %s", expectedDomain)
|
subdomain, _ := deployment["subdomain"].(string)
|
||||||
|
t.Logf("Deployment subdomain: %s", subdomain)
|
||||||
t.Logf("Deployment URLs: %v", urls)
|
t.Logf("Deployment URLs: %v", urls)
|
||||||
|
|
||||||
foundCorrectFormat := false
|
foundCorrectFormat := false
|
||||||
@ -304,28 +306,37 @@ func TestDeployment_DomainFormat(t *testing.T) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// URL should contain the simple format: {name}.{baseDomain}
|
// URL should start with https://{name}-
|
||||||
if assert.Contains(t, urlStr, expectedDomain,
|
expectedPrefix := fmt.Sprintf("https://%s-", deploymentName)
|
||||||
"URL should contain %s", expectedDomain) {
|
if strings.HasPrefix(urlStr, expectedPrefix) {
|
||||||
foundCorrectFormat = true
|
foundCorrectFormat = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// URL should contain base domain
|
||||||
|
assert.Contains(t, urlStr, env.BaseDomain,
|
||||||
|
"URL should contain base domain %s", env.BaseDomain)
|
||||||
|
|
||||||
// URL should NOT contain node identifier pattern
|
// URL should NOT contain node identifier pattern
|
||||||
assert.NotContains(t, urlStr, ".node-",
|
assert.NotContains(t, urlStr, ".node-",
|
||||||
"URL should NOT have node identifier (got: %s)", urlStr)
|
"URL should NOT have node identifier (got: %s)", urlStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(urls) > 0 {
|
if len(urls) > 0 {
|
||||||
assert.True(t, foundCorrectFormat, "Should find URL with correct domain format")
|
assert.True(t, foundCorrectFormat, "Should find URL with correct domain format (https://{name}-{random}.{baseDomain})")
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("✓ Domain format verification passed")
|
t.Logf("✓ Domain format verification passed")
|
||||||
t.Logf(" - Expected: %s", expectedDomain)
|
t.Logf(" - Format: {name}-{random}.{baseDomain}")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Domain resolves via Host header", func(t *testing.T) {
|
t.Run("Domain resolves via Host header", func(t *testing.T) {
|
||||||
// Test that the simple domain format works
|
// Get the actual subdomain from the deployment
|
||||||
domain := env.BuildDeploymentDomain(deploymentName)
|
deployment := GetDeployment(t, env, deploymentID)
|
||||||
|
subdomain, _ := deployment["subdomain"].(string)
|
||||||
|
if subdomain == "" {
|
||||||
|
t.Skip("No subdomain set, skipping host header test")
|
||||||
|
}
|
||||||
|
domain := subdomain + "." + env.BaseDomain
|
||||||
|
|
||||||
resp := TestDeploymentWithHostHeader(t, env, domain, "/")
|
resp := TestDeploymentWithHostHeader(t, env, domain, "/")
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|||||||
@ -69,6 +69,7 @@ func TestNamespaceCluster_StatusPolling(t *testing.T) {
|
|||||||
t.Run("Status endpoint returns valid response", func(t *testing.T) {
|
t.Run("Status endpoint returns valid response", func(t *testing.T) {
|
||||||
// Test with a non-existent cluster ID (should return 404)
|
// Test with a non-existent cluster ID (should return 404)
|
||||||
req, _ := http.NewRequest("GET", env.GatewayURL+"/v1/namespace/status?id=non-existent-id", nil)
|
req, _ := http.NewRequest("GET", env.GatewayURL+"/v1/namespace/status?id=non-existent-id", nil)
|
||||||
|
req.Header.Set("Authorization", "Bearer "+env.APIKey)
|
||||||
|
|
||||||
resp, err := env.HTTPClient.Do(req)
|
resp, err := env.HTTPClient.Do(req)
|
||||||
require.NoError(t, err, "Should execute request")
|
require.NoError(t, err, "Should execute request")
|
||||||
@ -168,8 +169,8 @@ func TestDeployment_RandomSubdomain(t *testing.T) {
|
|||||||
|
|
||||||
tarballPath := filepath.Join("../testdata/tarballs/react-vite.tar.gz")
|
tarballPath := filepath.Join("../testdata/tarballs/react-vite.tar.gz")
|
||||||
|
|
||||||
// Create a deployment
|
// Create a deployment with unique name
|
||||||
deploymentName := "subdomain-test"
|
deploymentName := fmt.Sprintf("subdomain-test-%d", time.Now().UnixNano())
|
||||||
deploymentID := CreateTestDeployment(t, env, deploymentName, tarballPath)
|
deploymentID := CreateTestDeployment(t, env, deploymentName, tarballPath)
|
||||||
defer func() {
|
defer func() {
|
||||||
if !env.SkipCleanup {
|
if !env.SkipCleanup {
|
||||||
|
|||||||
@ -54,12 +54,12 @@ func DefaultTopology() *Topology {
|
|||||||
Name: "node-2",
|
Name: "node-2",
|
||||||
ConfigFilename: "node-2.yaml",
|
ConfigFilename: "node-2.yaml",
|
||||||
DataDir: "node-2",
|
DataDir: "node-2",
|
||||||
P2PPort: 4011,
|
P2PPort: 4002,
|
||||||
IPFSAPIPort: 4511,
|
IPFSAPIPort: 4502,
|
||||||
IPFSSwarmPort: 4111,
|
IPFSSwarmPort: 4102,
|
||||||
IPFSGatewayPort: 7511,
|
IPFSGatewayPort: 7502,
|
||||||
RQLiteHTTPPort: 5011,
|
RQLiteHTTPPort: 5002,
|
||||||
RQLiteRaftPort: 7011,
|
RQLiteRaftPort: 7002,
|
||||||
ClusterAPIPort: 9104,
|
ClusterAPIPort: 9104,
|
||||||
ClusterPort: 9106,
|
ClusterPort: 9106,
|
||||||
UnifiedGatewayPort: 6002,
|
UnifiedGatewayPort: 6002,
|
||||||
@ -70,12 +70,12 @@ func DefaultTopology() *Topology {
|
|||||||
Name: "node-3",
|
Name: "node-3",
|
||||||
ConfigFilename: "node-3.yaml",
|
ConfigFilename: "node-3.yaml",
|
||||||
DataDir: "node-3",
|
DataDir: "node-3",
|
||||||
P2PPort: 4002,
|
P2PPort: 4003,
|
||||||
IPFSAPIPort: 4502,
|
IPFSAPIPort: 4503,
|
||||||
IPFSSwarmPort: 4102,
|
IPFSSwarmPort: 4103,
|
||||||
IPFSGatewayPort: 7502,
|
IPFSGatewayPort: 7503,
|
||||||
RQLiteHTTPPort: 5002,
|
RQLiteHTTPPort: 5003,
|
||||||
RQLiteRaftPort: 7002,
|
RQLiteRaftPort: 7003,
|
||||||
ClusterAPIPort: 9114,
|
ClusterAPIPort: 9114,
|
||||||
ClusterPort: 9116,
|
ClusterPort: 9116,
|
||||||
UnifiedGatewayPort: 6003,
|
UnifiedGatewayPort: 6003,
|
||||||
@ -86,12 +86,12 @@ func DefaultTopology() *Topology {
|
|||||||
Name: "node-4",
|
Name: "node-4",
|
||||||
ConfigFilename: "node-4.yaml",
|
ConfigFilename: "node-4.yaml",
|
||||||
DataDir: "node-4",
|
DataDir: "node-4",
|
||||||
P2PPort: 4003,
|
P2PPort: 4004,
|
||||||
IPFSAPIPort: 4503,
|
IPFSAPIPort: 4504,
|
||||||
IPFSSwarmPort: 4103,
|
IPFSSwarmPort: 4104,
|
||||||
IPFSGatewayPort: 7503,
|
IPFSGatewayPort: 7504,
|
||||||
RQLiteHTTPPort: 5003,
|
RQLiteHTTPPort: 5004,
|
||||||
RQLiteRaftPort: 7003,
|
RQLiteRaftPort: 7004,
|
||||||
ClusterAPIPort: 9124,
|
ClusterAPIPort: 9124,
|
||||||
ClusterPort: 9126,
|
ClusterPort: 9126,
|
||||||
UnifiedGatewayPort: 6004,
|
UnifiedGatewayPort: 6004,
|
||||||
@ -102,12 +102,12 @@ func DefaultTopology() *Topology {
|
|||||||
Name: "node-5",
|
Name: "node-5",
|
||||||
ConfigFilename: "node-5.yaml",
|
ConfigFilename: "node-5.yaml",
|
||||||
DataDir: "node-5",
|
DataDir: "node-5",
|
||||||
P2PPort: 4004,
|
P2PPort: 4005,
|
||||||
IPFSAPIPort: 4504,
|
IPFSAPIPort: 4505,
|
||||||
IPFSSwarmPort: 4104,
|
IPFSSwarmPort: 4105,
|
||||||
IPFSGatewayPort: 7504,
|
IPFSGatewayPort: 7505,
|
||||||
RQLiteHTTPPort: 5004,
|
RQLiteHTTPPort: 5005,
|
||||||
RQLiteRaftPort: 7004,
|
RQLiteRaftPort: 7005,
|
||||||
ClusterAPIPort: 9134,
|
ClusterAPIPort: 9134,
|
||||||
ClusterPort: 9136,
|
ClusterPort: 9136,
|
||||||
UnifiedGatewayPort: 6005,
|
UnifiedGatewayPort: 6005,
|
||||||
|
|||||||
@ -143,10 +143,10 @@ func (s *DeploymentService) generateSubdomain(ctx context.Context, name, namespa
|
|||||||
// subdomainExists checks if a subdomain is already registered globally
|
// subdomainExists checks if a subdomain is already registered globally
|
||||||
func (s *DeploymentService) subdomainExists(ctx context.Context, subdomain string) (bool, error) {
|
func (s *DeploymentService) subdomainExists(ctx context.Context, subdomain string) (bool, error) {
|
||||||
type existsRow struct {
|
type existsRow struct {
|
||||||
Exists int `db:"exists"`
|
Found int `db:"found"`
|
||||||
}
|
}
|
||||||
var rows []existsRow
|
var rows []existsRow
|
||||||
query := `SELECT 1 as exists FROM global_deployment_subdomains WHERE subdomain = ? LIMIT 1`
|
query := `SELECT 1 as found FROM global_deployment_subdomains WHERE subdomain = ? LIMIT 1`
|
||||||
err := s.db.Query(ctx, &rows, query, subdomain)
|
err := s.db.Query(ctx, &rows, query, subdomain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user