@@ -61,36 +61,36 @@ pub async fn create_namespace(
61
61
62
62
#[ cfg( test) ]
63
63
mod tests {
64
- use super :: * ;
65
- use kube:: Client ;
66
- use kube:: Config ;
67
- use mockito:: Server ;
64
+ use super :: create_namespace;
65
+ use k8s_openapi:: api:: core:: v1:: Namespace ;
66
+ use kube:: { api:: ObjectMeta , Client , Config } ;
67
+ use wiremock:: {
68
+ matchers:: { body_partial_json, method, path, query_param} ,
69
+ Mock , MockServer , ResponseTemplate ,
70
+ } ;
68
71
69
72
#[ tokio:: test]
70
73
async fn create_new_namespace ( ) {
71
- let mut server = Server :: new_async ( ) . await ;
72
- let mock_patch_test_namespace = server
73
- . mock (
74
- "PATCH" ,
75
- "/api/v1/namespaces/test?&fieldManager=sessionspaces" ,
76
- )
77
- . with_status ( 201 )
78
- . with_header ( "content-type" , "application/json" )
79
- . with_body (
80
- r#"{
81
- "apiVersion": "v1",
82
- "kind": "Namespace",
83
- "metadata": {
84
- "name": "test"
85
- }
86
- }"# ,
87
- )
88
- . create ( ) ;
89
- let config = Config :: new ( server. url ( ) . parse ( ) . unwrap ( ) ) ;
74
+ let server = MockServer :: start ( ) . await ;
75
+ let namespace = Namespace {
76
+ metadata : ObjectMeta {
77
+ name : Some ( "cm37235-3" . to_string ( ) ) ,
78
+ ..Default :: default ( )
79
+ } ,
80
+ ..Default :: default ( )
81
+ } ;
82
+ let _mock = Mock :: given ( method ( "PATCH" ) )
83
+ . and ( path ( "/api/v1/namespaces/cm37235-3" ) )
84
+ . and ( query_param ( "fieldManager" , "sessionspaces" ) )
85
+ . and ( body_partial_json ( namespace. clone ( ) ) )
86
+ . respond_with ( ResponseTemplate :: new ( 201 ) . set_body_json ( namespace) )
87
+ . expect ( 1 )
88
+ . mount ( & server)
89
+ . await ;
90
+ let config = Config :: new ( server. uri ( ) . parse ( ) . unwrap ( ) ) ;
90
91
let k8s_client = Client :: try_from ( config) . unwrap ( ) ;
91
- create_namespace ( "test " . to_string ( ) , k8s_client)
92
+ create_namespace ( "cm37235-3 " . to_string ( ) , k8s_client)
92
93
. await
93
94
. unwrap ( ) ;
94
- mock_patch_test_namespace. assert ( ) ;
95
95
}
96
96
}
0 commit comments