2
* Copyright (C) 2012 10gen Inc.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Affero General Public License, version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Affero General Public License for more details.
13
* You should have received a copy of the GNU Affero General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
#include "mongo/pch.h"
19
#include "mongo/s/type_shard.h"
20
#include "mongo/unittest/unittest.h"
25
using mongo::ShardType;
28
TEST(Validity, Empty) {
30
BSONObj emptyObj = BSONObj();
32
ASSERT(shard.parseBSON(emptyObj, &errMsg));
33
ASSERT_EQUALS(errMsg, "");
34
ASSERT_FALSE(shard.isValid(NULL));
37
TEST(Validity, MissingName) {
39
BSONObj obj = BSON(ShardType::host("localhost:27017"));
41
ASSERT(shard.parseBSON(obj, &errMsg));
42
ASSERT_EQUALS(errMsg, "");
43
ASSERT_FALSE(shard.isValid(NULL));
46
TEST(Validity, MissingHost) {
48
BSONObj obj = BSON(ShardType::name("shard0000"));
50
ASSERT(shard.parseBSON(obj, &errMsg));
51
ASSERT_EQUALS(errMsg, "");
52
ASSERT_FALSE(shard.isValid(NULL));
55
TEST(Validity, OnlyMandatory) {
57
BSONObj obj = BSON(ShardType::name("shard0000") <<
58
ShardType::host("localhost:27017"));
60
ASSERT(shard.parseBSON(obj, &errMsg));
61
ASSERT_EQUALS(errMsg, "");
62
ASSERT_TRUE(shard.isValid(NULL));
65
TEST(Validity, AllOptionalsPresent) {
67
BSONObj obj = BSON(ShardType::name("shard0000") <<
68
ShardType::host("localhost:27017") <<
69
ShardType::draining(true) <<
70
ShardType::maxSize(100));
72
ASSERT(shard.parseBSON(obj, &errMsg));
73
ASSERT_EQUALS(errMsg, "");
74
ASSERT_TRUE(shard.isValid(NULL));
77
TEST(Validity, BadType) {
79
BSONObj obj = BSON(ShardType::name() << 0);
81
ASSERT((!shard.parseBSON(obj, &errMsg)) && (errMsg != ""));
84
} // unnamed namespace