Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
42dfe524
Commit
42dfe524
authored
Feb 11, 2025
by
Tanmay Verma
Committed by
GitHub
Feb 11, 2025
Browse files
test: Add unit test to protocol module (#165)
Co-authored-by:
Ryan McCormick
<
rmccormick@nvidia.com
>
parent
dee73d91
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
0 deletions
+75
-0
runtime/rust/src/protocols.rs
runtime/rust/src/protocols.rs
+75
-0
No files found.
runtime/rust/src/protocols.rs
View file @
42dfe524
...
@@ -49,3 +49,78 @@ pub struct ModelMetaData {
...
@@ -49,3 +49,78 @@ pub struct ModelMetaData {
pub
component
:
Component
,
pub
component
:
Component
,
pub
router_type
:
RouterType
,
pub
router_type
:
RouterType
,
}
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
#[test]
fn
test_component_creation
()
{
let
component
=
Component
{
name
:
"test_name"
.to_string
(),
namespace
:
"test_namespace"
.to_string
(),
};
assert_eq!
(
component
.name
,
"test_name"
);
assert_eq!
(
component
.namespace
,
"test_namespace"
);
}
#[test]
fn
test_endpoint_creation
()
{
let
endpoint
=
Endpoint
{
name
:
"test_endpoint"
.to_string
(),
component
:
"test_component"
.to_string
(),
namespace
:
"test_namespace"
.to_string
(),
};
assert_eq!
(
endpoint
.name
,
"test_endpoint"
);
assert_eq!
(
endpoint
.component
,
"test_component"
);
assert_eq!
(
endpoint
.namespace
,
"test_namespace"
);
}
#[test]
fn
test_router_type_default
()
{
let
default_router
=
RouterType
::
default
();
assert_eq!
(
default_router
,
RouterType
::
PushRandom
);
}
#[test]
fn
test_router_type_serialization
()
{
let
router_round_robin
=
RouterType
::
PushRoundRobin
;
let
router_random
=
RouterType
::
PushRandom
;
let
serialized_round_robin
=
serde_json
::
to_string
(
&
router_round_robin
)
.unwrap
();
let
serialized_random
=
serde_json
::
to_string
(
&
router_random
)
.unwrap
();
assert_eq!
(
serialized_round_robin
,
"
\"
push_round_robin
\"
"
);
assert_eq!
(
serialized_random
,
"
\"
push_random
\"
"
);
}
#[test]
fn
test_router_type_deserialization
()
{
let
round_robin
:
RouterType
=
serde_json
::
from_str
(
"
\"
push_round_robin
\"
"
)
.unwrap
();
let
random
:
RouterType
=
serde_json
::
from_str
(
"
\"
push_random
\"
"
)
.unwrap
();
assert_eq!
(
round_robin
,
RouterType
::
PushRoundRobin
);
assert_eq!
(
random
,
RouterType
::
PushRandom
);
}
#[test]
fn
test_model_metadata_creation
()
{
let
component
=
Component
{
name
:
"test_component"
.to_string
(),
namespace
:
"test_namespace"
.to_string
(),
};
let
metadata
=
ModelMetaData
{
name
:
"test_model"
.to_string
(),
component
,
router_type
:
RouterType
::
PushRoundRobin
,
};
assert_eq!
(
metadata
.name
,
"test_model"
);
assert_eq!
(
metadata
.component.name
,
"test_component"
);
assert_eq!
(
metadata
.component.namespace
,
"test_namespace"
);
assert_eq!
(
metadata
.router_type
,
RouterType
::
PushRoundRobin
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment