summaryrefslogtreecommitdiff
path: root/tests/router_integration_tests.rs
blob: bf534f5537e100b478780d8fb9d8775ae430ac0f (plain)
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
use mesk::cfg::config::{Config, RouterConfig};
use mesk::router::manager::RouterManager;

// Integration tests for router functionality
// Note: These tests use a minimal configuration to avoid actually starting a full router

#[tokio::test]
async fn test_router_start_functionality() {
    let config = create_test_config(true); // Enable router for this test

    let result = RouterManager::new(&config).await;
    assert!(result.is_ok());

    let manager = result.unwrap();

    // Initially should not be running
    assert_eq!(manager.is_running(), false);

    // Attempt to start (this won't fully work without actual router dependencies)
    let start_result = manager.start().await;
    // This might fail due to missing dependencies, but the call should be accepted
    println!("Start result: {:?}", start_result);
}

#[tokio::test]
async fn test_router_stop_functionality() {
    let config = create_test_config(true); // Enable router for this test

    let result = RouterManager::new(&config).await;
    assert!(result.is_ok());

    let manager = result.unwrap();

    // Test stopping when not running
    manager.stop().await;
    assert_eq!(manager.is_running(), false);
}

#[tokio::test]
async fn test_router_restart_functionality() {
    let config = create_test_config(true); // Enable router for this test

    let result = RouterManager::new(&config).await;
    assert!(result.is_ok());

    let manager = result.unwrap();

    // Test restart (this won't fully work without actual router dependencies)
    let restart_result = manager.restart().await;
    // This might fail due to missing dependencies, but the call should be accepted
    println!("Restart result: {:?}", restart_result);
}

#[tokio::test]
async fn test_router_status_functionality() {
    let config = create_test_config(false); // Disable router for this test

    let result = RouterManager::new(&config).await;
    assert!(result.is_ok());

    let manager = result.unwrap();

    // Should not be running when router is disabled
    assert_eq!(manager.is_running(), false);
}

// Helper function to create test configuration
fn create_test_config(integrated_router_enabled: bool) -> Config {
    Config {
        repo: mesk::cfg::config::Repo {
            repo_url: "https://mesk.anthrill.i2p/repo/x86_64/".to_string(),
            auto_update: true,
            destination: (String::from("mesk"), String::from("mesk")),
            repo_http_url: Some("http://github.com/Anthrill/repo-mirror/x86_64".to_string()),
            i2p_http_proxy_port: 4444,
        },
        log: mesk::cfg::config::Log {
            log_file: "/tmp/mesk_test.log".to_string(),
            log_level: mesk::cfg::config::Loglevel::Debug,
        },
        paths: mesk::cfg::config::Paths {
            cache_dir: "/tmp/mesk_cache".to_string(),
            build_dir: "/tmp/mesk_build".to_string(),
            installed_db: "/tmp/mesk_pkgdb".to_string(),
        },
        router: RouterConfig {
            integrated_router: integrated_router_enabled,
            storage_path: "/tmp/mesk_test_router/".to_string(),
            http_proxy_port: 4447,
            socks_proxy_port: 4448,
            auto_update: false,
        },
    }
}