kube_sql/
lib.rs

1#[cfg(test)]
2mod tests {
3    use super::*;
4
5    #[test]
6    fn test_dummy_sqlparser() {
7        use sqlparser::ast::SetExpr;
8        use sqlparser::ast::{Query, Select, Statement};
9        use sqlparser::dialect::GenericDialect;
10        use sqlparser::parser::Parser;
11
12        let sql = "SELECT a, b, 123, myfunc(b) \
13                FROM table_1 \
14                WHERE a > b AND b < 100 \
15                ORDER BY a DESC, b";
16
17        let dialect = GenericDialect {}; // or AnsiDialect, or your own dialect ...
18
19        let mut ast = Parser::parse_sql(&dialect, sql).unwrap();
20        let mut stmt = ast.pop().unwrap();
21
22        match stmt {
23            Statement::Query(ref mut query) => {
24                match *query.body {
25                    SetExpr::Select(ref mut select) => {
26                        println!("{:?}", select.projection);
27                    }
28                    _ => {}
29                }
30                println!("{:?}", query.body);
31            }
32            _ => {}
33        }
34        println!("AST: {:?}", ast);
35    }
36
37    #[tokio::test]
38    async fn test_dummy_kube() -> Result<(), Box<dyn std::error::Error>> {
39        use futures::{StreamExt, TryStreamExt};
40        use k8s_openapi::api::core::v1::Pod;
41        use kube::{
42            api::{Api, ListParams, PostParams, ResourceExt},
43            Client,
44        };
45
46        // Infer the runtime environment and try to create a Kubernetes Client
47        let client = Client::try_default().await?;
48
49        // Read pods in the configured namespace into the typed interface from k8s-openapi
50        let pods: Api<Pod> = Api::default_namespaced(client);
51        for p in pods.list(&ListParams::default()).await? {
52            println!("found pod {}", p.name_any());
53        }
54        Ok(())
55    }
56}