1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// DNS integration tests temporarily disabled due to complex mocking requirements
// TODO: Enable when test infrastructure supports mock Docker and DNS resolver
/*
use minifly_core::models::{CreateMachineRequest, MachineConfig, GuestConfig};
use std::collections::HashMap;
mod common;
use common::*;
#[tokio::test]
async fn test_dns_registration() {
let (url, _handle) = start_test_server().await;
let client = test_client();
// Create an app
let create_app_req = CreateAppRequest {
app_name: "dns-test-app".to_string(),
org_slug: "personal".to_string(),
};
let response = client
.post(&format!("{}/apps", url))
.json(&create_app_req)
.send()
.await
.expect("Failed to create app");
assert_eq!(response.status(), 201);
// Create a machine
let mut env = HashMap::new();
env.insert("TEST_VAR".to_string(), "test_value".to_string());
let config = MachineConfig {
image: "alpine:latest".to_string(),
guest: GuestConfig {
cpu_kind: "shared".to_string(),
cpus: 1,
memory_mb: 256,
gpu_kind: None,
gpus: None,
kernel_args: None,
},
env: Some(env),
services: None,
mounts: None,
restart: None,
checks: None,
auto_destroy: None,
dns: None,
processes: None,
files: None,
init: None,
containers: None,
};
let req = CreateMachineRequest {
name: Some("dns-test-machine".to_string()),
region: Some("local".to_string()),
config,
skip_launch: Some(false),
skip_service_registration: None,
lease_ttl: None,
};
// Create machine - this should register with DNS
let response = client
.post(&format!("{}/apps/dns-test-app/machines", url))
.json(&req)
.send()
.await
.expect("Failed to create machine");
assert_eq!(response.status(), 201);
let machine_data: serde_json::Value = response.json().await.unwrap();
let machine_id = machine_data["id"].as_str().unwrap();
// Give DNS time to register
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
// We can't directly test DNS resolution here without access to AppState,
// but we've verified the machine was created successfully
// In a real integration test, we'd query the DNS resolver
// Cleanup
client
.delete(&format!("{}/apps/dns-test-app/machines/{}", url, machine_id))
.send()
.await
.expect("Failed to delete machine");
}
#[tokio::test]
async fn test_dns_cleanup_on_stop() {
let (url, _handle) = start_test_server().await;
let client = test_client();
// Create an app
let create_app_req = CreateAppRequest {
app_name: "dns-cleanup-app".to_string(),
org_slug: "personal".to_string(),
};
client
.post(&format!("{}/apps", url))
.json(&create_app_req)
.send()
.await
.expect("Failed to create app");
// Create and start a machine
let config = MachineConfig {
image: "alpine:latest".to_string(),
guest: GuestConfig {
cpu_kind: "shared".to_string(),
cpus: 1,
memory_mb: 256,
gpu_kind: None,
gpus: None,
kernel_args: None,
},
env: None,
services: None,
mounts: None,
restart: None,
checks: None,
auto_destroy: None,
dns: None,
processes: None,
files: None,
init: None,
containers: None,
};
let req = CreateMachineRequest {
name: Some("cleanup-test-machine".to_string()),
region: Some("local".to_string()),
config,
skip_launch: Some(false),
skip_service_registration: None,
lease_ttl: None,
};
let response = client
.post(&format!("{}/apps/dns-cleanup-app/machines", url))
.json(&req)
.send()
.await
.expect("Failed to create machine");
let machine_data: serde_json::Value = response.json().await.unwrap();
let machine_id = machine_data["id"].as_str().unwrap();
// Stop the machine - this should unregister from DNS
let stop_response = client
.post(&format!("{}/apps/dns-cleanup-app/machines/{}/stop", url, machine_id))
.send()
.await
.expect("Failed to stop machine");
assert_eq!(stop_response.status(), 200);
// Cleanup
client
.delete(&format!("{}/apps/dns-cleanup-app/machines/{}", url, machine_id))
.send()
.await
.expect("Failed to delete machine");
}
*/