| 51 | |
| 52 | |
| 53 | TEST(QuantitiesTest, FromStringValid) |
| 54 | { |
| 55 | // A single resource. |
| 56 | ResourceQuantities resourceQuantities = |
| 57 | CHECK_NOTERROR(ResourceQuantities::fromString("cpus:10")); |
| 58 | vector<pair<string, double>> expected = {{"cpus", 10}}; |
| 59 | EXPECT_EQ(expected, toVector(resourceQuantities)); |
| 60 | |
| 61 | resourceQuantities = |
| 62 | CHECK_NOTERROR(ResourceQuantities::fromString("cpus:3.14")); |
| 63 | expected = {{"cpus", 3.14}}; |
| 64 | EXPECT_EQ(expected, toVector(resourceQuantities)); |
| 65 | |
| 66 | // Whitespace is trimmed. |
| 67 | resourceQuantities = |
| 68 | CHECK_NOTERROR(ResourceQuantities::fromString(" cpus : 3.14 ; disk : 10 ")); |
| 69 | expected = {{"cpus", 3.14}, {"disk", 10}}; |
| 70 | EXPECT_EQ(expected, toVector(resourceQuantities)); |
| 71 | |
| 72 | // Zero value. |
| 73 | resourceQuantities = CHECK_NOTERROR(ResourceQuantities::fromString("cpus:0")); |
| 74 | EXPECT_EQ(0u, resourceQuantities.size()); |
| 75 | |
| 76 | // Two resources. |
| 77 | resourceQuantities = |
| 78 | CHECK_NOTERROR(ResourceQuantities::fromString("cpus:10.5;ports:1")); |
| 79 | expected = {{"cpus", 10.5}, {"ports", 1}}; |
| 80 | EXPECT_EQ(expected, toVector(resourceQuantities)); |
| 81 | |
| 82 | // Two resources with names out of alphabetical order. |
| 83 | resourceQuantities = |
| 84 | CHECK_NOTERROR(ResourceQuantities::fromString("ports:3;cpus:10.5")); |
| 85 | expected = {{"cpus", 10.5}, {"ports", 3}}; |
| 86 | EXPECT_EQ(expected, toVector(resourceQuantities)); |
| 87 | |
| 88 | // Duplicate resource names. |
| 89 | resourceQuantities = |
| 90 | CHECK_NOTERROR(ResourceQuantities::fromString("ports:3;cpus:1;cpus:10.5")); |
| 91 | expected = {{"cpus", 11.5}, {"ports", 3}}; |
| 92 | EXPECT_EQ(expected, toVector(resourceQuantities)); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | TEST(QuantitiesTest, FromStringInvalid) |
nothing calls this directly
no test coverage detected