| 39 | }; |
| 40 | |
| 41 | TEST_F(ClusterTest, CluseterSetNodes) { |
| 42 | Status s; |
| 43 | |
| 44 | auto config = storage_->GetConfig(); |
| 45 | // don't start workers |
| 46 | config->workers = 0; |
| 47 | Server server(storage_.get(), config); |
| 48 | // we don't need the server resource, so just stop it once it's started |
| 49 | server.Stop(); |
| 50 | server.Join(); |
| 51 | |
| 52 | Cluster cluster(&server, {"127.0.0.1"}, 3002); |
| 53 | |
| 54 | const std::string invalid_fields = |
| 55 | "07c37dfeb235213a872192d90877d0cd55635b91 127.0.0.1 30004 " |
| 56 | "slave"; |
| 57 | s = cluster.SetClusterNodes(invalid_fields, 1, false); |
| 58 | ASSERT_FALSE(s.IsOK()); |
| 59 | ASSERT_TRUE(s.Msg() == "Invalid cluster nodes info"); |
| 60 | |
| 61 | const std::string invalid_node_id = |
| 62 | "07c37dfeb235213a872192d90877d0cd55635b9 127.0.0.1 30004 " |
| 63 | "slave 07c37dfeb235213a872192d90877d0cd55635b92"; |
| 64 | s = cluster.SetClusterNodes(invalid_node_id, 1, false); |
| 65 | ASSERT_FALSE(s.IsOK()); |
| 66 | ASSERT_TRUE(s.Msg() == "Invalid cluster node id"); |
| 67 | |
| 68 | const std::string invalid_port = |
| 69 | "67ed2db8d677e59ec4a4cefb06858cf2a1a89fa1 127.0.0.1 unknown " |
| 70 | "master 07c37dfeb235213a872192d90877d0cd55635b91 5461-10922"; |
| 71 | s = cluster.SetClusterNodes(invalid_port, 1, false); |
| 72 | ASSERT_FALSE(s.IsOK()); |
| 73 | ASSERT_TRUE(s.Msg() == "Invalid cluster node port"); |
| 74 | |
| 75 | const std::string slave_has_no_master = |
| 76 | "07c37dfeb235213a872192d90877d0cd55635b91 127.0.0.1 30004 " |
| 77 | "slave -"; |
| 78 | s = cluster.SetClusterNodes(slave_has_no_master, 1, false); |
| 79 | ASSERT_FALSE(s.IsOK()); |
| 80 | ASSERT_TRUE(s.Msg() == "Invalid cluster node id"); |
| 81 | |
| 82 | const std::string master_has_master = |
| 83 | "67ed2db8d677e59ec4a4cefb06858cf2a1a89fa1 127.0.0.1 30002 " |
| 84 | "master 07c37dfeb235213a872192d90877d0cd55635b91 5461-10922"; |
| 85 | s = cluster.SetClusterNodes(master_has_master, 1, false); |
| 86 | ASSERT_FALSE(s.IsOK()); |
| 87 | ASSERT_TRUE(s.Msg() == "Invalid cluster node id"); |
| 88 | |
| 89 | const std::string invalid_slot_range = |
| 90 | "67ed2db8d677e59ec4a4cefb06858cf2a1a89fa1 127.0.0.1 30002 " |
| 91 | "master - 5461-0"; |
| 92 | s = cluster.SetClusterNodes(invalid_slot_range, 1, false); |
| 93 | ASSERT_FALSE(s.IsOK()); |
| 94 | ASSERT_TRUE(s.Msg() == "Slot is out of range"); |
| 95 | |
| 96 | const std::string invalid_slot_id = |
| 97 | "67ed2db8d677e59ec4a4cefb06858cf2a1a89fa1 127.0.0.1 30002 " |
| 98 | "master - 54610"; |
nothing calls this directly
no test coverage detected