zilliz 1.4.3

TUI and CLI tool for managing Zilliz Cloud clusters and Milvus operations
Documentation
// Copyright (c) 2026 Zilliz Inc. All rights reserved.
//
// PROPRIETARY AND CONFIDENTIAL
//
// This file contains proprietary information of Zilliz Inc.
//
// No part of this file may be reproduced, stored, transmitted,
// or disclosed to any third party without the prior written
// permission of Zilliz Inc.
//
// Unauthorized use is strictly prohibited.

use zilliz::model::loader::ModelLoader;

mod control_plane {
    use super::*;

    fn load() -> zilliz::model::loader::Models {
        ModelLoader::load_builtin().expect("Failed to load models")
    }

    #[test]
    fn test_load_control_plane() {
        let models = load();
        assert!(models.control_plane.resources.contains_key("cluster"));
        assert!(models.control_plane.resources.contains_key("project"));
        // `endpoint` is omitted in the built-in JSON; the resolver falls back
        // to DEFAULT_CONTROL_PLANE_ENDPOINT.
        assert!(models.control_plane.endpoint.is_none());
        assert_eq!(
            models.control_plane.resolved_endpoint(),
            zilliz::model::DEFAULT_CONTROL_PLANE_ENDPOINT
        );
    }

    #[test]
    fn test_cluster_operations() {
        let models = load();
        let cluster = &models.control_plane.resources["cluster"];
        for op in &[
            "list",
            "describe",
            "delete",
            "suspend",
            "resume",
            "modify",
            "providers",
            "regions",
        ] {
            assert!(
                cluster.operations.contains_key(*op),
                "Missing cluster operation: {}",
                op
            );
        }
    }

    #[test]
    fn test_project_operations() {
        let models = load();
        let project = &models.control_plane.resources["project"];
        for op in &["list", "describe", "create", "delete", "upgrade"] {
            assert!(
                project.operations.contains_key(*op),
                "Missing project operation: {}",
                op
            );
        }
    }

    #[test]
    fn test_backup_operations() {
        let models = load();
        assert!(models.control_plane.resources.contains_key("backup"));
        let backup = &models.control_plane.resources["backup"];
        for op in &[
            "create",
            "list",
            "describe",
            "delete",
            "export",
            "restore-cluster",
            "restore-collection",
            "describe-policy",
            "update-policy",
        ] {
            assert!(
                backup.operations.contains_key(*op),
                "Missing backup operation: {}",
                op
            );
        }
    }

    #[test]
    fn test_import_operations() {
        let models = load();
        assert!(models.control_plane.resources.contains_key("import"));
        let import = &models.control_plane.resources["import"];
        for op in &["start", "list", "status"] {
            assert!(
                import.operations.contains_key(*op),
                "Missing import operation: {}",
                op
            );
        }
    }

    #[test]
    fn test_backup_describe_has_two_path_params() {
        let models = load();
        let describe = &models.control_plane.resources["backup"].operations["describe"];
        let path_params: Vec<&str> = describe
            .params
            .iter()
            .filter(|p| p.is_path_param())
            .map(|p| p.name.as_str())
            .collect();
        assert_eq!(path_params.len(), 2);
        assert!(path_params.contains(&"clusterId"));
        assert!(path_params.contains(&"backupId"));
    }

    #[test]
    fn test_project_upgrade_uses_patch() {
        let models = load();
        let upgrade = &models.control_plane.resources["project"].operations["upgrade"];
        assert_eq!(upgrade.method(), "PATCH");
    }

    #[test]
    fn test_project_delete_uses_delete_with_project_path() {
        let models = load();
        let delete = &models.control_plane.resources["project"].operations["delete"];

        assert_eq!(delete.method(), "DELETE");
        assert_eq!(delete.http.path, "/v2/projects/{projectId}");
        let path_params: Vec<_> = delete
            .params
            .iter()
            .filter(|param| param.position.as_deref() == Some("path"))
            .collect();
        assert_eq!(path_params.len(), 1);
        assert_eq!(path_params[0].name, "projectId");
        assert!(path_params[0].required);
    }

    #[test]
    fn test_auth_config_present() {
        let models = load();
        let auth = models
            .control_plane
            .auth
            .as_ref()
            .expect("Auth config should be present");
        assert!(!auth.auth0_domain.is_empty());
        assert!(!auth.client_id.is_empty());
        assert!(!auth.login_api.is_empty());
    }
}

mod data_plane {
    use super::*;

    fn load() -> zilliz::model::loader::Models {
        ModelLoader::load_builtin().expect("Failed to load models")
    }

    #[test]
    fn test_load_data_plane() {
        let models = load();
        assert!(models.data_plane.resources.contains_key("collection"));
        assert!(models.data_plane.resources.contains_key("vector"));
        assert!(models.data_plane.endpoint.is_none());
    }

    #[test]
    fn test_collection_operations() {
        let models = load();
        let collection = &models.data_plane.resources["collection"];
        for op in &[
            "list",
            "describe",
            "create",
            "drop",
            "has",
            "rename",
            "load",
            "release",
            "get-stats",
            "get-load-state",
            "flush",
            "compact",
        ] {
            assert!(
                collection.operations.contains_key(*op),
                "Missing collection operation: {}",
                op
            );
        }
    }

    #[test]
    fn test_vector_operations() {
        let models = load();
        let vector = &models.data_plane.resources["vector"];
        for op in &[
            "search",
            "hybrid-search",
            "query",
            "insert",
            "upsert",
            "get",
            "delete",
        ] {
            assert!(
                vector.operations.contains_key(*op),
                "Missing vector operation: {}",
                op
            );
        }
    }

    #[test]
    fn test_database_operations() {
        let models = load();
        assert!(models.data_plane.resources.contains_key("database"));
        let db = &models.data_plane.resources["database"];
        for op in &["create", "list", "describe", "drop"] {
            assert!(
                db.operations.contains_key(*op),
                "Missing database operation: {}",
                op
            );
        }
    }

    #[test]
    fn test_index_operations() {
        let models = load();
        let index = &models.data_plane.resources["index"];
        for op in &["create", "list", "describe", "drop"] {
            assert!(
                index.operations.contains_key(*op),
                "Missing index operation: {}",
                op
            );
        }
    }

    #[test]
    fn test_partition_operations() {
        let models = load();
        let partition = &models.data_plane.resources["partition"];
        for op in &[
            "create",
            "list",
            "has",
            "get-stats",
            "load",
            "release",
            "drop",
        ] {
            assert!(
                partition.operations.contains_key(*op),
                "Missing partition operation: {}",
                op
            );
        }
    }

    #[test]
    fn test_user_operations() {
        let models = load();
        let user = &models.data_plane.resources["user"];
        for op in &[
            "create",
            "list",
            "describe",
            "drop",
            "update-password",
            "grant-role",
            "revoke-role",
        ] {
            assert!(
                user.operations.contains_key(*op),
                "Missing user operation: {}",
                op
            );
        }
    }

    #[test]
    fn test_role_operations() {
        let models = load();
        let role = &models.data_plane.resources["role"];
        for op in &[
            "create",
            "list",
            "describe",
            "drop",
            "grant-privilege",
            "revoke-privilege",
        ] {
            assert!(
                role.operations.contains_key(*op),
                "Missing role operation: {}",
                op
            );
        }
    }

    #[test]
    fn test_alias_operations() {
        let models = load();
        let alias = &models.data_plane.resources["alias"];
        for op in &["create", "list", "describe", "alter", "drop"] {
            assert!(
                alias.operations.contains_key(*op),
                "Missing alias operation: {}",
                op
            );
        }
    }

    #[test]
    fn test_collection_create_has_body_param() {
        let models = load();
        let create_op = &models.data_plane.resources["collection"].operations["create"];
        assert_eq!(create_op.body_param.as_deref(), Some("--body"));
    }

    #[test]
    fn test_hybrid_search_has_body_param() {
        let models = load();
        let hs = &models.data_plane.resources["vector"].operations["hybrid-search"];
        assert_eq!(hs.body_param.as_deref(), Some("--body"));
    }

    #[test]
    fn test_hybrid_search_has_array_and_object_params() {
        let models = load();
        let hs = &models.data_plane.resources["vector"].operations["hybrid-search"];
        let search_param = hs.params.iter().find(|p| p.name == "search").unwrap();
        let rerank_param = hs.params.iter().find(|p| p.name == "rerank").unwrap();
        assert_eq!(search_param.param_type, "array");
        assert_eq!(rerank_param.param_type, "object");
    }

    #[test]
    fn test_on_demand_cluster_uses_on_demand_paths() {
        let models = ModelLoader::load_builtin().expect("Failed to load models");
        let qc = &models.control_plane.resources["on-demand-cluster"];
        assert_eq!(
            qc.operations["list"].path(),
            "/v2/clusters/onDemandClusters"
        );
        assert_eq!(
            qc.operations["describe"].path(),
            "/v2/clusters/onDemandClusters/{clusterId}"
        );
        assert_eq!(
            qc.operations["delete"].path(),
            "/v2/clusters/onDemandClusters/{clusterId}"
        );
    }

    #[test]
    fn test_privatelink_uses_private_endpoint_paths() {
        let models = ModelLoader::load_builtin().expect("Failed to load models");
        let pl = &models.control_plane.resources["privatelink"];
        assert_eq!(
            pl.operations["list-services"].path(),
            "/v2/privateEndpointServices"
        );
        assert_eq!(
            pl.operations["list"].path(),
            "/v2/projects/{projectId}/privateEndpoints"
        );
        assert_eq!(
            pl.operations["create"].path(),
            "/v2/projects/{projectId}/privateEndpoints"
        );
        assert_eq!(
            pl.operations["delete"].path(),
            "/v2/projects/{projectId}/privateEndpoints/{endpointId}"
        );
        assert_eq!(
            pl.operations["add-whitelist"].path(),
            "/v2/projects/{projectId}/privateEndpointWhitelist"
        );
    }
}